07.1 · API
Chain JSON-RPC
The Ethereum methods Galileo and mainnet actually answer.
Both networks speak Ethereum JSON-RPC over HTTPS. Galileo is evmrpc-testnet.0g.ai, chain id 16602. Mainnet is evmrpc.0g.ai, chain id 16661. The development RPCs are for building. Production traffic should move to a provider such as QuickNode or Ankr when you outgrow them.
Send POST with content-type application/json. A batch array also works on many nodes. The examples below are single calls so a failure is obvious.
eth_chainId
RPCWhich chain answered. This is the first test on every OS.
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_chainId",
"params": []
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x40da"
}- 0x40da is 16602, Galileo. Mainnet returns 0x4115, which is 16661.
- cast chain-id --rpc-url evmrpc-testnet.0g.ai prints the decimal.
eth_blockNumber
RPCThe latest block. Call it twice. The second number should be higher.
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber",
"params": []
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x10f447"
}- The result is a hex block height. cast block-number prints it as a decimal.
eth_getBalance
RPCNative 0G balance in wei, at a block tag.
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getBalance",
"params": ["0xYOUR_ADDRESS", "latest"]
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x16345785d8a0000"
}- Divide the integer by 10^18. 0x16345785d8a0000 is 0.1 0G.
- The faucet desk on this portal calls this method for you and formats the result. It does not sign anything.
eth_getTransactionCount
RPCThe next nonce. Read it before you build a raw transaction.
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getTransactionCount",
"params": ["0xYOUR_ADDRESS", "pending"]
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x3"
}eth_gasPrice
RPCA gas price hint, in wei.
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_gasPrice",
"params": []
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0x3b9aca00"
}- Prefer the wallet’s own fee suggestion when a person is signing. This call is for scripts and for maintainers checking that the RPC is alive.
eth_sendRawTransaction
RPCBroadcast a signed transaction. The node will not sign for you.
{
"jsonrpc": "2.0",
"id": 1,
"method": "eth_sendRawTransaction",
"params": ["0xSIGNED_RAW_TX"]
}{
"jsonrpc": "2.0",
"id": 1,
"result": "0xTRANSACTION_HASH"
}- Build the raw transaction with cast or ethers, using chain id 16602 on Galileo so the signature is not valid on mainnet.
- Then poll eth_getTransactionReceipt with that hash. A status of 0x1 is success. 0x0 is a revert. null means it is not in a block yet.