C-Chain API
This page is an overview of the C-Chain API associated with AvalancheGo.
Note
Ethereum has its own notion of networkID and chainID. These have no relationship to Avalanche's view of networkID and chainID and are purely internal to the C-Chain. On Mainnet, the C-Chain uses 1 and 43114 for these values. On the Fuji Testnet, it uses 1 and 43113 for these values. networkID and chainID can also be obtained using the net_version and eth_chainId methods.
Ethereum APIs
Endpoints
JSON-RPC Endpoints
To interact with C-Chain via the JSON-RPC endpoint:
/ext/bc/C/rpcTo interact with other instances of the EVM via the JSON-RPC endpoint:
/ext/bc/blockchainID/rpcwhere blockchainID is the ID of the blockchain running the EVM.
WebSocket Endpoints
info
On the public API node, it only supports C-Chain websocket API calls for API methods that don't exist on the C-Chain's HTTP API
To interact with C-Chain via the websocket endpoint:
/ext/bc/C/wsFor example, to interact with the C-Chain's Ethereum APIs via websocket on localhost, you can use:
ws://127.0.0.1:9650/ext/bc/C/wsTip
On localhost, use ws://. When using the Public API or another
host that supports encryption, use wss://.
To interact with other instances of the EVM via the websocket endpoint:
/ext/bc/blockchainID/wswhere blockchainID is the ID of the blockchain running the EVM.
Standard Ethereum APIs
Avalanche offers an API interface identical to Geth's API except that it only supports the following services:
web3_net_eth_personal_txpool_debug_(note: this is turned off on the public API node.)
You can interact with these services the same exact way you'd interact with Geth (see exceptions below). See the Ethereum Wiki's JSON-RPC Documentation and Geth's JSON-RPC Documentation for a full description of this API.
info
For batched requests on the public API node , the maximum number of items is 40.
Exceptions
Starting with release v0.12.2, eth_getProof has a different behavior compared to geth:
- On archival nodes (nodes with
pruning-enabledset tofalse), queries for state proofs older than 24 hours preceding the last accepted block will be rejected by default. This can be adjusted withhistorical-proof-query-window, which defines the number of blocks before the last accepted block that can be queried for state proofs. Set this option to0to accept a state query for any block number. - On pruning nodes (nodes with
pruning-enabledset totrue), queries for state proofs outside the 32 block window after the last accepted block are always rejected.
Avalanche - Ethereum APIs
In addition to the standard Ethereum APIs, Avalanche offers eth_baseFee,
eth_maxPriorityFeePerGas, and eth_getChainConfig.
They use the same endpoint as standard Ethereum APIs:
/ext/bc/C/rpceth_baseFee
Get the base fee for the next block.
Signature:
eth_baseFee() -> {}result is the hex value of the base fee for the next block.
Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"eth_baseFee",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/rpcExample Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x34630b8a00"
}eth_maxPriorityFeePerGas
Get the priority fee needed to be included in a block.
Signature:
eth_maxPriorityFeePerGas() -> {}result is hex value of the priority fee needed to be included in a block.
Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"eth_maxPriorityFeePerGas",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/rpcExample Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x2540be400"
}For more information on dynamic fees see the C-Chain section of the transaction fee documentation.
Admin APIs
The Admin API provides administrative functionality for the EVM.
Endpoint
/ext/bc/C/adminMethods
admin_startCPUProfiler
Starts a CPU profile that writes to the specified file.
Signature:
admin_startCPUProfiler() -> {}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"admin_startCPUProfiler",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/adminadmin_stopCPUProfiler
Stops the CPU profile.
Signature:
admin_stopCPUProfiler() -> {}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"admin_stopCPUProfiler",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/adminadmin_memoryProfile
Runs a memory profile writing to the specified file.
Signature:
admin_memoryProfile() -> {}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"admin_memoryProfile",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/adminadmin_lockProfile
Runs a mutex profile writing to the specified file.
Signature:
admin_lockProfile() -> {}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"admin_lockProfile",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/adminadmin_setLogLevel
Sets the log level for the EVM.
Signature:
admin_setLogLevel({
level: string
}) -> {}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"admin_setLogLevel",
"params" :[{
"level": "debug"
}]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/adminadmin_getVMConfig
Returns the current VM configuration.
Signature:
admin_getVMConfig() -> {
config: {
// VM configuration fields
}
}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"admin_getVMConfig",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/adminAvalanche-Specific APIs
Endpoint
/ext/bc/C/avaxMethods
avax.getUTXOs
Gets all UTXOs for the specified addresses.
Signature:
avax.getUTXOs({
addresses: [string],
sourceChain: string,
startIndex: {
address: string,
utxo: string
},
limit: number,
encoding: string
}) -> {
utxos: [string],
endIndex: {
address: string,
utxo: string
},
numFetched: number,
encoding: string
}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.getUTXOs",
"params" :[{
"addresses": ["X-avax1..."],
"sourceChain": "X",
"limit": 100,
"encoding": "hex"
}]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avaxavax.issueTx
Issues a transaction to the network.
Signature:
avax.issueTx({
tx: string,
encoding: string
}) -> {
txID: string
}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.issueTx",
"params" :[{
"tx": "0x...",
"encoding": "hex"
}]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avaxavax.getAtomicTxStatus
Returns the status of the specified atomic transaction.
Signature:
avax.getAtomicTxStatus({
txID: string
}) -> {
status: string,
blockHeight: number (optional)
}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.getAtomicTxStatus",
"params" :[{
"txID": "2QouvNW..."
}]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avaxavax.getAtomicTx
Returns the specified atomic transaction.
Signature:
avax.getAtomicTx({
txID: string,
encoding: string
}) -> {
tx: string,
encoding: string,
blockHeight: number (optional)
}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.getAtomicTx",
"params" :[{
"txID": "2QouvNW...",
"encoding": "hex"
}]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avaxavax.version
Returns the version of the VM.
Signature:
avax.version() -> {
version: string
}Example Call:
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.version",
"params" :[]
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avaxIs this guide helpful?