An X-Chain Client. XChainClient
Given a JSON representation of this Virtual Machine's genesis state, create the byte representation of that state.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const genesis = await client.xChain.buildGenesis({
networkID: 16,
genesisData: {
asset1: {
name: "myFixedCapAsset",
symbol: "MFCA",
initialState: {
fixedCap: [
{
amount: 100000,
address: "avax13ery2kvdrkd2nkquvs892gl8hg7mq4a6ufnrn6"
}
]
}
}
}
})
Get the balances of all assets controlled by given addresses.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const balances = await client.xChain.getAllBalances({
addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"]
})
Get information about an asset.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const asset = await client.xChain.getAssetDescription({
assetID: "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z"
})
Get the balance of an asset controlled by given addresses.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const balance = await client.xChain.getBalance({
addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"],
assetID: "FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z"
})
Get a block by its ID.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const block = await client.xChain.getBlock({
blockID: "d7WYmb8VeZNHsny3EJCwMm6QA37s1EHwMxw1Y71V3FqPZ5EFG",
encoding: "hex"
})
Get a block by its height.
Get the height of the last accepted block.
Get a transaction by its ID.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const tx = await client.xChain.getTx({
txID: "11111111111111111111111111111111LpoYY",
encoding: "hex"
})
Get the transaction fee for this node.
Get the status of a transaction.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const status = await client.xChain.getTxStatus({
txID: "11111111111111111111111111111111LpoYY"
})
Get the UTXOs for a set of addresses.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const utxos = await client.xChain.getUTXOs({
addresses: ["X-avax18jma8ppw3nhx5r4ap8clazz0dps7rv5ukulre5"],
sourceChain: "P"
})
Send a signed transaction to the network.
import { createAvalancheClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createAvalancheClient({
chain: avalanche,
transport: {
type: "http",
},
})
const txID = await client.xChain.issueTx({
tx: "0x00000009de31b4d8b22991d51aa6aa1fc733f23a851a8c9400000000000186a0000000005f041280000000005f9ca900000030390000000000000001fceda8f90fcb5d30614b99d79fc4baa29307762668f16eb0259a57c2d3b78c875c86ec2045792d4df2d926c40f829196e0bb97ee697af71f5b0a966dabff749634c8b729855e937715b0e44303fd1014daedc752006011b730",
encoding: "hex"
})
import { createXChainClient} from '@avalanche-sdk/client'
import { avalanche } from '@avalanche-sdk/client/chains'
const client = createXChainClient({
chain: avalanche,
transport: {
type: "http",
},
})
// Get asset information
const asset = await client.getAssetDescription({ assetID: 'asset-id' })
// Get balance for an address
const balance = await client.getBalance({ address: 'X-avax...' })
Creates an X-Chain (Exchange Chain) Client with a given transport configured for a Chain.
The X-Chain Client is an interface to interact with the Avalanche Exchange Chain through JSON-RPC API methods. The Exchange Chain is responsible for: