Skip to content

JSON-RPC APIs

Introduction

Asset Hub provides Ethereum compatibility through its JSON-RPC interface, allowing developers to interact with the chain using familiar Ethereum tooling and methods. This document outlines the supported Ethereum JSON-RPC methods and provides examples of how to use them.

This article uses the Westend Asset Hub endpoint to interact with:

https://westend-asset-hub-eth-rpc.polkadot.io

Available Methods

eth_accounts

Returns a list of addresses owned by the client. Reference.

Parameters:

None

Example:

eth_accounts
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_accounts",
    "params":[],
    "id":1
}'

eth_blockNumber

Returns the number of the most recent block. Reference.

Parameters:

None

Example:

eth_blockNumber
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_blockNumber",
    "params":[],
    "id":1
}'

eth_call

Executes a new message call immediately without creating a transaction. Reference.

Parameters:

  • transaction object - the transaction call object:
    • to string - recipient address of the call. Must be a 20-byte data string
    • data string - hash of the method signature and encoded parameters. Must be a data string
    • from string - (optional) sender's address for the call. Must be a 20-byte data string
    • gas string - (optional) gas limit to execute the call. Must be a quantity string
    • gasPrice string - (optional) gas price per unit of gas. Must be a quantity string
    • value string - (optional) value in wei to send with the call. Must be a quantity string
  • blockValue string - (optional) block tag or block number to execute the call at. Must be a quantity string or a default block parameter

Example:

eth_call
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_call",
    "params":[{
        "to": "INSERT_RECIPIENT_ADDRESS",
        "data": "INSERT_ENCODED_CALL"
    }, "INSERT_BLOCK_VALUE"],
    "id":1
}'

Ensure to replace the INSERT_RECIPIENT_ADDRESS, INSERT_ENCODED_CALL, and INSERT_BLOCK_VALUE with the proper values.


eth_chainId

Returns the chain ID used for signing transactions. Reference.

Parameters:

None

Example:

eth_chainId
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_chainId",
    "params":[],
    "id":1
}'

eth_estimateGas

Estimates gas required for a transaction. Reference.

Parameters:

  • transaction object - the transaction call object:
    • to string - recipient address of the call. Must be a 20-byte data string
    • data string - hash of the method signature and encoded parameters. Must be a data string
    • from string - (optional) sender's address for the call. Must be a 20-byte data string
    • gas string - (optional) gas limit to execute the call. Must be a quantity string
    • gasPrice string - (optional) gas price per unit of gas. Must be a quantity string
    • value string - (optional) value in wei to send with the call. Must be a quantity string
  • blockValue string - (optional) block tag or block number to execute the call at. Must be a quantity string or a default block parameter

Example:

eth_estimateGas
curl -X POST https://westend-asset-hub-eth-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_estimateGas",
    "params":[{
        "to": "INSERT_RECIPIENT_ADDRESS",
        "data": "INSERT_ENCODED_FUNCTION_CALL"
    }],
    "id":1
}'

Ensure to replace the INSERT_RECIPIENT_ADDRESS and INSERT_ENCODED_CALL with the proper values.


eth_gasPrice

Returns the current gas price in Wei. Reference.

Parameters:

None

Example:

eth_gasPrice
curl -X POST https://westend-asset-hub-eth-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_gasPrice",
    "params":[],
    "id":1
}'

eth_getBalance

Returns the balance of a given address. Reference.

Parameters:

Example:

eth_getBalance
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_getBalance",
    "params":["INSERT_ADDRESS", "INSERT_BLOCK_VALUE"],
    "id":1
}'

Ensure to replace the INSERT_ADDRESS and INSERT_BLOCK_VALUE with the proper values.


eth_getBlockByHash

Returns information about a block by its hash. Reference.

Parameters:

  • blockHash string – the hash of the block to retrieve. Must be a 32 byte data string
  • fullTransactions boolean – if true, returns full transaction details; if false, returns only transaction hashes

Example:

eth_getBlockByHash
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_getBlockByHash",
    "params":["INSERT_BLOCK_HASH", INSERT_BOOLEAN],
    "id":1
}'

Ensure to replace the INSERT_BLOCK_HASH and INSERT_BOOLEAN with the proper values.


eth_getBlockByNumber

Returns information about a block by its number. Reference.

Parameters:

  • blockValue string - (optional) the block value to be fetched. Must be a quantity string or a default block parameter
  • fullTransactions boolean – if true, returns full transaction details; if false, returns only transaction hashes

Example:

eth_getBlockByNumber
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_getBlockByNumber",
    "params":["INSERT_BLOCK_VALUE", INSERT_BOOLEAN],
    "id":1
}'

Ensure to replace the INSERT_BLOCK_VALUE and INSERT_BOOLEAN with the proper values.


eth_getCode

Returns the code at a given address. Reference.

Parameters:

Example:

eth_getCode
curl -X POST https://westend-asset-hub-eth-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_getCode",
    "params":["INSERT_ADDRESS", "INSERT_BLOCK_VALUE"],
    "id":1
}'

Ensure to replace the INSERT_ADDRESS and INSERT_BLOCK_VALUE with the proper values.


eth_getStorageAt

Returns the value from a storage position at a given address. Reference.

Parameters:

  • address string - contract or account address to query code. Must be a 20-byte data string
  • storageKey string - position in storage to retrieve data from. Must be a quantity string
  • blockValue string - (optional) the block value to be fetched. Must be a quantity string or a default block parameter

Example:

eth_getStorageAt
curl -X POST https://westend-asset-hub-eth-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_getStorageAt",
    "params":["INSERT_ADDRESS", "INSERT_STORAGE_KEY", "INSERT_BLOCK_VALUE"],
    "id":1
}'

Ensure to replace the INSERT_ADDRESS, INSERT_STORAGE_KEY, and INSERT_BLOCK_VALUE with the proper values.

eth_getTransactionCount

Returns the number of transactions sent from an address (nonce). Reference.

Parameters:

Example:

eth_getTransactionCount
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_getTransactionCount",
    "params":["INSERT_ADDRESS", "INSERT_BLOCK_VALUE"],
    "id":1
}'

Ensure to replace the INSERT_ADDRESS and INSERT_BLOCK_VALUE with the proper values.


eth_maxPriorityFeePerGas

Returns an estimate of the current priority fee per gas, in Wei, to be included in a block.

Parameters:

None

Example:

eth_maxPriorityFeePerGas
curl -X POST https://westend-asset-hub-eth-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_maxPriorityFeePerGas",
    "params":[],
    "id":1
}'

eth_sendRawTransaction

Submits a raw transaction. Reference.

Parameters:

  • callData string - signed transaction data. Must be a data string

Example:

eth_sendRawTransaction
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_sendRawTransaction",
    "params":["INSERT_CALL_DATA"],
    "id":1
}'

Ensure to replace the INSERT_CALL_DATA with the proper values.


eth_sendTransaction

Creates and sends a new transaction. Reference.

Parameters:

  • transaction object - the transaction object:
    • from string - address sending the transaction. Must be a 20-byte data string
    • to string - (optional) recipient address. No need to provide this value when deploying a contract. Must be a 20-byte data string
    • gas string - (optional, default: 90000) gas limit for execution. Must be a quantity string
    • gasPrice string - (optional) gas price per unit. Must be a quantity string
    • value string - (optional) amount of Ether to send. Must be a quantity string
    • data string - (optional) contract bytecode or encoded method call. Must be a data string
    • nonce string - (optional) transaction nonce. Must be a quantity string

Example:

eth_sendTransaction
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"eth_sendTransaction",
    "params":[{
        "from": "INSERT_SENDER_ADDRESS",
        "to": "INSERT_RECIPIENT_ADDRESS",
        "gas": "INSERT_GAS_LIMIT",
        "gasPrice": "INSERT_GAS_PRICE",
        "value": "INSERT_VALUE",
        "input": "INSERT_INPUT_DATA",
        "nonce": "INSERT_NONCE"
    }],
    "id":1
}'

Ensure to replace the INSERT_SENDER_ADDRESS, INSERT_RECIPIENT_ADDRESS, INSERT_GAS_LIMIT, INSERT_GAS_PRICE, INSERT_VALUE, INSERT_INPUT_DATA, and INSERT_NONCE with the proper values.


net_version

Returns the current network ID as a string. Reference.

Parameters:

None

Example:

net_version
curl -X POST https://westend-asset-hub-rpc.polkadot.io \
-H "Content-Type: application/json" \
--data '{
    "jsonrpc":"2.0",
    "method":"net_version",
    "params":[],
    "id":1
}'

Response Format

All responses follow the standard JSON-RPC 2.0 format:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": ... // The return value varies by method
}

Error Handling

If an error occurs, the response will include an error object:

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -32000,
        "message": "Error message here"
    }
}
Last update: March 6, 2025
| Created: March 6, 2025