A Go backend system that allows users to pay for shared RPC access using EVM deposits. Users can purchase computational units, generate an API key, and use it to access RPC services, with payments handled on-chain.
- Vault deposits: Users deposit native currency to a vault to fund RPC access.
- Computational units: Each RPC request consumes units, which are deducted from the vault.
- API key generation: Unique API keys are issued per user for authenticated RPC usage.
- Ethereum payments: Users can top up their vault by sending native currency.
- Shared RPC pool: Multiple users can utilize the same backend RPC while maintaining individual usage accounting.
-
Deposit native currency User sends native currency to the vault smart contract.
-
Buy units Vault converts deposits into computational units for RPC usage.
-
Generate API key Backend generates a unique key for the user, linked to their deposited balance.
-
Use RPC User sends requests with API key; each request consumes units.
-
Top up Users can deposit more native currency anytime to increase their computational units.
git clone https://github.com/typicalHuman/rpc-together.git
cd rpc-together
go mod tidy
go run main.goRPC endpoint used for paid access
This is the RPC URL that users ultimately access using their API keys. All computational unit (CU) usage is measured against requests sent to this endpoint.
Example:
- Your own hosted RPC
- A premium provider endpoint
RPC endpoint for the blockchain where the vault contract is deployed
This can be any reliable public or free RPC for the target chain.
Deployed RPCTogetherVault contract address
Must match the chain specified by BASE_CHAIN_RPC_URL.
PostgreSQL database connection string
Example format:
postgres://user:password@host:5432/dbname
Payment plan identifier from the smart contract
A bytes32 value returned when a payment plan is created on-chain.
The backend uses this to associate deposits with a specific RPC pricing plan.