# Make your first paid RPC call

Get a free quote with HTTP. To buy the result, use a Base mainnet wallet that can sign typed data and send a transaction. No SolidRPC account, API key or SolidRPC package is required. This walkthrough uses a regular wallet and one payment channel.

## Get a price

Save the following as `request.json`. This asks Base for its chain ID.

```json
{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}
```

```sh
curl -sS https://rpc.solidrpc.io/x402/batch/evm/8453 \
  -H 'Content-Type: application/json' \
  --data-binary @request.json -o offer.json -w '%{http_code}\n'
```

Expect HTTP `402`. Read `accepts[0]` in the response. Its `amount` is a string in millionths of USDC. For this call, `"3"` means **0.000003 USDC**. The chain ID in the URL selects the network you want to read. The payment network comes from the offer.

Check the owner’s spending limit, the quote expiry and the current pilot terms before signing. For this guide the offer must specify `batch-settlement`, payment network `eip155:8453`, native Base USDC, and `voucherManager: "server"`. Match the recipient and asset to the live capabilities. Keep the whole offer, including its opaque quote value. [Capabilities](https://rpc.solidrpc.io/x402/batch/capabilities) · [Pilot terms](https://rpc.solidrpc.io/x402/batch/terms)

## Fund one channel

If you already use this funded channel, go straight to signing the voucher. For a new channel, get approval for a deposit and Base gas. The suggested deposit is **0.01 USDC**. You can spend part of it and withdraw the rest. The wallet needs native USDC and a little ETH on **Base mainnet**.

Use these Base contracts for the pilot. The escrow holds the deposit. The collector receives the USDC transfer authorization as part of the escrow deposit call. An ordinary token transfer to the merchant or either contract does not open a channel.

| Contract | Base mainnet address |
|---|---|
| Native USDC | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |
| x402 batch escrow | `0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003` |
| USDC deposit collector | `0x4020806089470a89826cB9fB1f4059150b550004` |

1. Build the channel config using the fields below in exactly this order. Generate and save a random 32-byte `salt` once. Keep the same config for later calls and top-ups.

   | Field | Solidity type | Value |
   |---|---|---|
   | payer | address | Your wallet |
   | payerAuthorizer | address | Your wallet |
   | receiver | address | `accepts[0].payTo` |
   | receiverAuthorizer | address | `accepts[0].extra.receiverAuthorizer` |
   | token | address | `accepts[0].asset` |
   | withdrawDelay | uint40 | `accepts[0].extra.withdrawDelay` in seconds |
   | salt | bytes32 | Your saved channel salt |

2. Read `getChannelId(config) returns (bytes32)` on the escrow through your existing Base RPC. Use the tuple types above as the ABI for `config`. Save the returned channel ID. The escrow’s `channels(bytes32) returns (uint128 balance, uint128 totalClaimed)` exposes its on-chain state. SolidRPC can already have accepted vouchers that are still waiting for collection.
3. Select the approved deposit amount in integer units. For 0.01 USDC it is `10000`. Generate a **fresh, separate** random uint256 `depositSalt`. Set `nonce = keccak256(abi.encode(channelId, depositSalt))` using the types `bytes32,uint256`. Use ordinary ABI encoding.
4. Sign the following EIP-712 typed data with the payer wallet. The USDC domain uses the token name and version from `accepts[0].extra`, chain ID `8453`, and the USDC contract as `verifyingContract`. Use Unix **seconds**. Set `validAfter = 0` and `validBefore = now + accepts[0].maxTimeoutSeconds`.

   ```text
   ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)
   from = payer
   to = USDC deposit collector
   value = approved deposit amount
   ```

5. Build `collectorData = abi.encode(validAfter, validBefore, depositSalt, signature)` using types `uint256,uint256,uint256,bytes`. Use your wallet to estimate gas and send **one** transaction to the escrow calling `deposit(config, amount, collector, collectorData)`. The argument types are the config tuple above, `uint128`, `address`, `bytes`. Send zero ETH as the transaction value. ETH pays only the network fee. Save the transaction hash and confirm its successful receipt before spending the deposit. If the wallet times out, look up the original transaction before attempting another deposit.

## Sign one voucher and get the result

If the original quote expired during funding, request a fresh quote before signing the first voucher. For a new channel, the starting charge is zero. On a used channel, start from the last charge SolidRPC accepted, including any charges waiting for collection. Resolve an uncertain earlier payment before signing the next voucher on that channel.

Sign EIP-712 typed data using your wallet’s typed-data signer. This is an off-chain signature. Use this exact domain and primary type:

```json
{
  "domain": {
    "name": "x402 Batch Settlement",
    "version": "1",
    "chainId": 8453,
    "verifyingContract": "0x4020074e9dF2ce1deE5A9C1b5c3f541D02a10003"
  },
  "primaryType": "Voucher",
  "types": {
    "Voucher": [
      {"name":"channelId","type":"bytes32"},
      {"name":"maxClaimableAmount","type":"uint128"}
    ]
  }
}
```

The typed-data `message` has two fields. Set `channelId` to your saved channel ID and `maxClaimableAmount` to the last accepted charge plus this quote. For the first call in this example the amount is `3`. For a second distinct call at the same price it is `6`. Check that the cumulative amount fits both the deposit and the approved spending limit.

Generate one UUID for this RPC operation. The following JavaScript shows how to assemble the HTTP header after signing. `offer` is the JSON from the 402, `config` is your channel object with named fields, and `signature` is the wallet’s hex voucher signature.

```js
const extensions = structuredClone(offer.extensions);
extensions["payment-identifier"].info.id = operationId;
const payment = {
  x402Version: 2,
  resource: offer.resource,
  accepted: offer.accepts[0],
  payload: {
    type: "voucher",
    channelConfig: config,
    voucher: {channelId, maxClaimableAmount: String(cumulativeAmount), signature}
  },
  extensions
};
const header = Buffer.from(JSON.stringify(payment), "utf8").toString("base64");
```

Save the original RPC body, operation ID and signed payment privately before sending. POST the **same RPC body** to the **same URL**. Here, `requestBody` is the original JSON-RPC object.

```js
const response = await fetch("https://rpc.solidrpc.io/x402/batch/evm/8453", {
  method: "POST",
  redirect: "error",
  headers: {"Content-Type": "application/json", "PAYMENT-SIGNATURE": header},
  body: JSON.stringify(requestBody)
});
const result = await response.json();
```

The example’s successful result is `{"jsonrpc":"2.0","id":1,"result":"0x2105"}`. Keep the response and update the accepted charge once.

If the response is lost or pending, retry the identical request with the saved signed payment, or retrieve its receipt with that payment header. A new operation ID starts another purchase. The API reference lists the receipt route and response states. [API reference](https://rpc.solidrpc.io/x402/batch/openapi.json)

## Try your own log query

Replace the example body with your own `eth_getLogs` request. Use an address or topic filter and explicit block numbers. A 10,000-block inclusive range ends at `fromBlock + 9999`. Check support for your chosen network in capabilities, then request a fresh quote. Compare the logs against your existing RPC using the same filter and blocks. Start timing after the channel is funded. Record calls with the quote ready separately from calls that include the quote request.

To withdraw unspent funds, the payer calls `initiateWithdraw(config, amount)` on the escrow, then `finalizeWithdraw(config)` after the 72-hour delay. The amount is a `uint128` in token units. Both transactions need Base gas. Stop using a channel once withdrawal starts.
