X-Chain API
This page is an overview of the X-Chain API associated with AvalancheGo.
The X-Chain, Avalanche's native platform for creating and trading assets, is an instance of the Avalanche Virtual Machine (AVM). This API allows clients to create and trade assets on the X-Chain and other instances of the AVM.
Format
This API uses the json 2.0
RPC format. For more information on making JSON RPC calls, see
here.
Endpoints
/ext/bc/X
to interact with the X-Chain.
/ext/bc/blockchainID
to interact with other AVM instances, where blockchainID
is the ID of a
blockchain running the AVM.
Methods
avm.buildGenesis
Given a JSON representation of this Virtual Machine’s genesis state, create the byte representation of that state.
Endpoint
This call is made to the AVM’s static API endpoint:
/ext/vm/avm
Note: addresses should not include a chain prefix (that is X-
) in calls to the static API endpoint
because these prefixes refer to a specific chain.
Signature:
Encoding specifies the encoding format to use for arbitrary bytes, that is the genesis bytes that are
returned. Can only be hex
when a value is provided.
genesisData
has this form:
Example Call:
Example Response:
avm.getAddressTxs
:::caution Deprecated as of v1.9.12.
:::
Returns all transactions that change the balance of the given address. A transaction is said to change an address's balance if either is true:
- A UTXO that the transaction consumes was at least partially owned by the address.
- A UTXO that the transaction produces is at least partially owned by the address.
:::tip
Note: Indexing (index-transactions
) must be enabled in the X-chain config.
:::
Signature:
Request Parameters:
address
: The address for which we're fetching related transactionsassetID
: Only return transactions that changed the balance of this asset. Must be an ID or an alias for an asset.pageSize
: Number of items to return per page. Optional. Defaults to 1024.
Response Parameter:
txIDs
: List of transaction IDs that affected the balance of this address.cursor
: Page number or offset. Use this in request to get the next page.
Example Call:
Example Response:
avm.getAllBalances
:::caution Deprecated as of v1.9.12.
:::
Get the balances of all assets controlled by a given address.
Signature:
Example Call:
Example Response:
avm.getAssetDescription
Get information about an asset.
Signature:
assetID
is the id of the asset for which the information is requested.name
is the asset’s human-readable, not necessarily unique name.symbol
is the asset’s symbol.denomination
determines how balances of this asset are displayed by user interfaces. If denomination is 0, 100 units of this asset are displayed as 100. If denomination is 1, 100 units of this asset are displayed as 10.0. If denomination is 2, 100 units of this asset are displays as .100, etc.
:::note The AssetID for AVAX differs depending on the network you are on.
Mainnet: FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z
Testnet: U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK
For finding the assetID
of other assets, this [info] might be useful.
Also, avm.getUTXOs
returns the assetID
in its output.
:::
Example Call:
Example Response:
avm.getBalance
:::caution Deprecated as of v1.9.12.
:::
Get the balance of an asset controlled by a given address.
Signature:
address
owner of the assetassetID
id of the asset for which the balance is requested
Example Call:
Example Response:
avm.getBlock
Returns the block with the given id.
Signature:
Request:
blockID
is the block ID. It should be in cb58 format.encoding
is the encoding format to use. Can be eitherhex
orjson
. Defaults tohex
.
Response:
block
is the transaction encoded toencoding
.encoding
is theencoding
.
Hex Example
Example Call:
Example Response:
avm.getBlockByHeight
Returns block at the given height.
Signature:
Request:
blockHeight
is the block height. It should be instring
format.encoding
is the encoding format to use. Can be eitherhex
orjson
. Defaults tohex
.
Response:
block
is the transaction encoded toencoding
.encoding
is theencoding
.
Hex Example
Example Call:
Example Response:
avm.getHeight
Returns the height of the last accepted block.
Signature:
Example Call:
Example Response:
avm.getTx
Returns the specified transaction. The encoding
parameter sets the format of the returned
transaction. Can be either "hex"
or "json"
. Defaults to "hex"
.
Signature:
Example Call:
Example Response:
Where:
credentials
is a list of this transaction's credentials. Each credential proves that this transaction's creator is allowed to consume one of this transaction's inputs. Each credential is a list of signatures.unsignedTx
is the non-signature portion of the transaction.networkID
is the ID of the network this transaction happened on. (Avalanche Mainnet is1
.)blockchainID
is the ID of the blockchain this transaction happened on. (Avalanche Mainnet X-Chain is2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM
.)- Each element of
outputs
is an output (UTXO) of this transaction that is not being exported to another chain. - Each element of
inputs
is an input of this transaction which has not been imported from another chain. - Import Transactions have additional fields
sourceChain
andimportedInputs
, which specify the blockchain ID that assets are being imported from, and the inputs that are being imported. - Export Transactions have additional fields
destinationChain
andexportedOutputs
, which specify the blockchain ID that assets are being exported to, and the UTXOs that are being exported.
An output contains:
assetID
: The ID of the asset being transferred. (The Mainnet Avax ID isFvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z
.)fxID
: The ID of the FX this output uses.output
: The FX-specific contents of this output.
Most outputs use the secp256k1 FX, look like this:
The above output can be consumed after Unix time locktime
by a transaction that has signatures
from threshold
of the addresses in addresses
.
avm.getTxFee
Get the fees of the network.
Signature:
txFee
is the default fee for making transactions.createAssetTxFee
is the fee for creating a new asset.
All fees are denominated in nAVAX.
Example Call:
Example Response:
avm.getTxStatus
:::caution Deprecated as of v1.10.0. :::
Get the status of a transaction sent to the network.
Signature:
status
is one of:
Accepted
: The transaction is (or will be) accepted by every nodeProcessing
: The transaction is being voted on by this nodeRejected
: The transaction will never be accepted by any node in the networkUnknown
: The transaction hasn’t been seen by this node
Example Call:
Example Response:
avm.getUTXOs
Gets the UTXOs that reference a given address. If sourceChain
is specified, then it will retrieve
the atomic UTXOs exported from that chain to the X Chain.
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 (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
X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5
and X-avax1d09qn852zcy03sfc9hay2llmn9hsgnw4tp3dv6
.
This gives response:
Since numFetched
is the same as limit
, we can tell that there may be more UTXOs that were not
fetched. We call the method again, this time with startIndex
:
This gives response:
Since numFetched
is less than limit
, we know that we are done fetching UTXOs and don’t need to
call this method again.
Suppose we want to fetch the UTXOs exported from the P Chain to the X Chain in order to build an
ImportTx. Then we need to call GetUTXOs with the sourceChain
argument in order to retrieve the
atomic UTXOs:
This gives response:
avm.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:
wallet.issueTx
Send a signed transaction to the network and assume the TX will be accepted. encoding
specifies
the format of the signed transaction. Can only be hex
when a value is provided.
This call is made to the wallet API endpoint:
/ext/bc/X/wallet
:::caution Endpoint deprecated as of v1.9.12.
:::
Signature:
Example Call:
Example Response: