# Create rpc

URL: https://docs.hanzo.ai/docs/openapi/web3/post-web3-rpc-by-chain

> Forwards a JSON-RPC call to the named chain and returns its answer unchanged.

`POST /v1/web3/rpc/{chain}`

> [Web3 →](https://docs.hanzo.ai/docs/openapi/web3) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                            |
| ------------- | ------------------------------------------ |
| **Address**   | `https://api.hanzo.ai/v1/web3/rpc/{chain}` |
| **Method**    | `POST`                                     |
| **Operation** | `post_web3_rpc_by_chain`                   |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`     |

Forwards a JSON-RPC call to the named chain and returns its answer
unchanged. Only declared chains are reachable, and only to a caller with a
validated principal — this is the deployment's upstream, not an open relay.

## Request

6 fields, body `application/json` (required).

| Field     | In   | Type   | Required | Description                                               |
| --------- | ---- | ------ | -------- | --------------------------------------------------------- |
| `chain`   | path | string | yes      | Chain is the registry id, from the URL.                   |
| `chain`   | body | string | —        | Chain is the registry id, from the URL.                   |
| `id`      | body | any    | —        | ID is echoed back untouched.                              |
| `jsonrpc` | body | string | —        | JSONRPC must be "2.0" when present.                       |
| `method`  | body | string | —        | Method is the RPC method, e.g. eth\_getBalance.           |
| `params`  | body | any    | —        | Params is the method's parameters, passed through unread. |

## Response

| Status    | Body            | Meaning |
| --------- | --------------- | ------- |
| `200`     | web3.rpcOut     | ok      |
| `default` | problem-details | refused |

`200` body — 6 fields.

| Field           | In   | Type            | Always | Description                                                                                                                   |
| --------------- | ---- | --------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------- |
| `error`         | body | web3.rpcError   | —      |                                                                                                                               |
| `error.code`    | body | integer (int64) | —      | Code is the JSON-RPC error code the chain reported, passed through as it came.                                                |
| `error.message` | body | string          | —      | Message is the chain's own explanation, e.g. "execution reverted".                                                            |
| `id`            | body | any             | —      | ID is the request's id, echoed back untouched — any JSON value, because JSON-RPC lets the caller choose.                      |
| `jsonrpc`       | body | string          | —      | JSONRPC is always "2.0".                                                                                                      |
| `result`        | body | any             | —      | Result is the chain's answer, passed through unread: an eth\_getBalance result is a 0x-quantity string, a block is an object. |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo web3 rpc add <chain>
```

**SDK**

**.ts**

```ts
import { Configuration, Web3Api } from 'hanzoai';

const api = new Web3Api(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postWeb3RpcByChain({ chain: 'chain', chain: "<chain>", id: "<id>" });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import Web3Api

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = Web3Api(client).post_web3_rpc_by_chain(chain='chain', chain="<chain>", id="<id>")
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.Web3API.PostWeb3RpcByChain(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, web3_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = web3_api::post_web3_rpc_by_chain(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.Web3Api;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new Web3Api(client).postWeb3RpcByChain();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/web3/rpc/<chain> \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "chain": "<chain>",
       "id": "<id>"
     }'
```

**MCP**

MCP reaches **web3** through the `web3` tool, which names its 3 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_web3_chains"
         }
       }
     }'
```

---

[Web3 API](https://docs.hanzo.ai/docs/openapi/web3) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
