C-Chain API
This page is an overview of the C-Chain API associated with AvalancheGo.
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:
To interact with other instances of the EVM via the JSON-RPC endpoint:
where blockchainID
is the ID of the blockchain running the EVM.
WebSocket Endpoints
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:
For example, to interact with the C-Chain's Ethereum APIs via websocket on localhost, you can use:
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:
where 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 the Ethereum Wiki's JSON-RPC Documentation and Geth's JSON-RPC Documentation for a full description of this API.
For batched requests on the public API node , the maximum number of items is 40. We are working on to support a larger batch size.
Avalanche - Ethereum APIs
In addition to the standard Ethereum APIs, Avalanche offers eth_getAssetBalance
, eth_baseFee
,
eth_maxPriorityFeePerGas
, and eth_getChainConfig
.
They use the same endpoint as standard Ethereum APIs:
eth_getAssetBalance
Retrieves the balance of first class Avalanche Native Tokens on the C-Chain (excluding AVAX,
which must be fetched with eth_getBalance
).
The AssetID for AVAX differs depending on the network you are on.
Mainnet: FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z
Testnet: U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK
For finding the assetID
of other assets, please note that
avax.getUTXOs
and avax.getAtomicTx
return the assetID
in
their output.
Signature:
address
owner of the assetblk
is the block number or hash at which to retrieve the balanceassetID
id of the asset for which the balance is requested
Example Call:
Example Response:
eth_baseFee
Get the base fee for the next block.
Signature:
result
is the hex value of the base fee for the next block.
Example Call:
Example Response:
eth_maxPriorityFeePerGas
Get the priority fee needed to be included in a block.
Signature:
result
is hex value of the priority fee needed to be included in a block.
Example Call:
Example Response:
For more information on dynamic fees see the C-Chain section of the transaction fee documentation.
eth_getChainConfig
eth_getChainConfig
returns chain config. This API is enabled by default with internal-eth
namespace.
Signature:
Example Call:
Example Response:
Avalanche Specific APIs
To interact with the avax
specific RPC calls on the C-Chain:
To interact with other instances of the EVM AVAX endpoints:
avax.export
Not recommended for use on Mainnet. See warning notice in Keystore API.
Export an asset from the C-Chain to X-Chain or P-Chain. If exporting to the X-Chain, you must call the
X-Chain's avm.import
.
Signature:
to
is the X-Chain or P-Chain address the asset is sent to.amount
is the amount of the asset to send.assetID
is the ID of the asset. To export AVAX use"AVAX"
as theassetID
.baseFee
is the base fee that should be used when creating the transaction. If omitted, a suggested fee will be used.username
is the user that controls the address that transaction will be sent from.password
isusername
‘s password.
Example Call:
Example Response:
avax.exportAVAX
Not recommended for use on Mainnet. See warning notice in Keystore API.
DEPRECATED—instead use avax.export
.
Send AVAX from the C-Chain to X-Chain or P-Chain. If exporting to the X-Chain, you must call the
X-Chain's avm.import
with assetID AVAX
on the X-Chain to complete the transfer.
Signature:
Request:
to
is X-Chain or P-Chain address the asset is sent to.amount
is the amount of the asset to send.baseFee
is the base fee that should be used when creating the transaction. If omitted, a suggested fee will be used.username
is the user that controls the address that transaction will be sent from.password
isusername
‘s password.
Response:
txID
is the TXID of the completed ExportTx.
Example Call:
Example Response:
avax.exportKey
Not recommended for use on Mainnet. See warning notice in Keystore API.
Get the private key that controls a given address. The returned private key can be added to a user
with avax.importKey
.
Signature:
Request:
username
must controladdress
.address
is the address for which you want to export the corresponding private key. It should be in hex format.
Response:
privateKey
is the CB58 encoded string representation of the private key that controlsaddress
. It has aPrivateKey-
prefix and can be used to import a key viaavax.importKey
.privateKeyHex
is the hex string representation of the private key that controlsaddress
. It can be used to import an account into Core or other wallets, like MetaMask.
Example Call:
Example Response:
avax.getAtomicTx
Gets a transaction by its ID. Optional encoding parameter to specify the format for the returned
transaction. Can only be hex
when a value is provided.
Signature:
Request:
txID
is the transaction ID. It should be in cb58 format.encoding
is the encoding format to use. Can only behex
when a value is provided.
Response:
tx
is the transaction encoded toencoding
.encoding
is theencoding
.blockHeight
is the height of the block which the transaction was included in.
Example Call:
Example Response:
avax.getAtomicTxStatus
Get the status of an atomic transaction sent to the network.
Signature:
status
is one of:
Accepted
: The transaction is (or will be) accepted by every node. Check theblockHeight
propertyProcessing
: The transaction is being voted on by this nodeDropped
: The transaction was dropped by this node because it thought the transaction invalidUnknown
: The transaction hasn't been seen by this node
Example Call:
Example Response:
avax.getUTXOs
Gets the UTXOs that reference a given address.
Signature:
utxos
is a list of UTXOs such that each UTXO references at least one address inaddresses
.- At most
limit
UTXOs are returned. Iflimit
is omitted or greater than 1024, it is set to 1024. - This method supports pagination.
endIndex
denotes the last UTXO returned. To get the next set of UTXOs, use the value ofendIndex
asstartIndex
in the next call. - If
startIndex
is omitted, will fetch all UTXOs up tolimit
. - When using pagination (that is when
startIndex
is provided), UTXOs are not guaranteed to be unique across multiple calls. That is, a UTXO may appear in the result of the first call, and then again in the second call. - When using pagination, consistency is not guaranteed across multiple calls. That is, the UTXO set of the addresses may have changed between calls.
encoding
sets the format for the returned UTXOs. Can only behex
when a value is provided.
Example
Suppose we want all UTXOs that reference at least one of
C-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5
.
This gives response:
avax.import
Not recommended for use on Mainnet. See warning notice in Keystore API.
Finalize the transfer of a non-AVAX or AVAX from X-Chain or P-Chain to the C-Chain.
Signature:
Request:
to
is the address the asset is sent to. This must be the same as theto
argument in the corresponding call to the X-Chain's or P-Chain'sexport
.sourceChain
is the ID or alias of the chain the asset is being imported from. To import funds from the X-Chain, use"X"
; for the P-Chain, use"P"
.baseFee
is the base fee that should be used when creating the transaction. If omitted, a suggested fee will be used.username
is the user that controls the address that transaction will be sent from.password
isusername
‘s password.
Response:
txID
is the ID of the completed ImportTx.
Example Call:
Example Response:
avax.importAVAX
Not recommended for use on Mainnet. See warning notice in Keystore API.
DEPRECATED—instead use avax.import
Finalize a transfer of AVAX from the X-Chain or P-Chain to the C-Chain.
Signature:
Request:
to
is the address the AVAX is sent to. It should be in hex format.sourceChain
is the ID or alias of the chain the AVAX is being imported from. To import funds from the X-Chain, use"X"
; for the P-Chain, use"P"
.baseFee
is the base fee that should be used when creating the transaction. If omitted, a suggested fee will be used.username
is the user that controls the address that transaction will be sent from.password
isusername
‘s password.
Response:
txID
is the ID of the completed ImportTx.
Example Call:
Example Response:
avax.importKey
Not recommended for use on Mainnet. See warning notice in Keystore API.
Give a user control over an address by providing the private key that controls the address.
Signature:
Request:
- Add
privateKey
tousername
's set of private keys.
Response:
address
is the addressusername
now controls with the private key. It will be in hex format.
Example Call:
Example Response:
avax.issueTx
Send a signed transaction to the network. encoding
specifies the format of the signed transaction.
Can only be hex
when a value is provided.
Signature:
Example Call:
Example Response:
Admin API
This API can be used for debugging. Note that the Admin API is disabled by default. To run a node
with the Admin API enabled, use C-Chain config flag--coreth-admin-api-enabled:true
.
Endpoint
admin.setLogLevel
Sets the log level of the C-Chain.
Signature:
level
is the log level to be set.
Example Call:
Example Response:
admin.startCPUProfiler
Starts a CPU profile.
Signature:
Example Call:
Example Response:
admin.stopCPUProfiler
Stops and writes a CPU profile.
Signature:
Example Call:
Example Response:
admin.memoryProfile
Runs and writes a memory profile.
Signature:
Example Call:
Example Response:
admin.lockProfile
Runs a mutex profile writing to the coreth_performance_c
directory.
Signature:
Example Call:
Example Response:
Last updated on