Avalanche SDK Client
    Preparing search index...

    Function createXChainClient

    • 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:

      • Creating and trading digital assets
      • Managing asset transfers
      • Handling atomic swaps
      • Creating and managing custom assets

      Type Parameters

      • transport extends Transport
      • chain extends undefined | Chain = undefined
      • accountOrAddress extends undefined | `0x${string}` | Account = undefined
      • rpcSchema extends undefined | RpcSchema = undefined
      • raw extends boolean = false

      Parameters

      Returns {
          buildGenesis: (args: BuildGenesisParameters) => Promise<BuildGenesisReturnType>;
          extend: <const client extends { [key: string]: unknown }>(
              fn: (
                  client: {
                      buildGenesis: ...;
                      extend: ...;
                      getAllBalances: ...;
                      getAssetDescription: ...;
                      getBalance: ...;
                      getBlock: ...;
                      getBlockByHeight: ...;
                      getHeight: ...;
                      getTx: ...;
                      getTxFee: ...;
                      getTxStatus: ...;
                      getUTXOs: ...;
                      issueTx: ...;
                  },
              ) => client,
          ) => { [K in (...)
          | (...)
          | (...)]: (...)[(...)] };
          getAllBalances: (args: GetAllBalancesParameters) => Promise<GetAllBalancesReturnType>;
          getAssetDescription: (args: GetAssetDescriptionParameters) => Promise<GetAssetDescriptionReturnType>;
          getBalance: (args: GetBalanceParameters) => Promise<GetBalanceReturnType>;
          getBlock: (args: GetBlockParameters) => Promise<XChainBlockType>;
          getBlockByHeight: (args: GetBlockByHeightParameters) => Promise<XChainBlockType>;
          getHeight: () => Promise<GetHeightReturnType>;
          getTx: (args: GetTxParameters) => Promise<XChainTransactionType>;
          getTxFee: () => Promise<GetTxFeeReturnType>;
          getTxStatus: (args: GetTxStatusParameters) => Promise<GetTxStatusReturnType>;
          getUTXOs: (args: GetUTXOsParameters) => Promise<GetUTXOsReturnType>;
          issueTx: (args: IssueTxParameters) => Promise<IssueTxReturnType>;
      }

      An X-Chain Client. XChainClient

      • buildGenesis: (args: BuildGenesisParameters) => Promise<BuildGenesisReturnType>

        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"
        }
        ]
        }
        }
        }
        })
      • extend: <const client extends { [key: string]: unknown }>(
            fn: (
                client: {
                    buildGenesis: ...;
                    extend: ...;
                    getAllBalances: ...;
                    getAssetDescription: ...;
                    getBalance: ...;
                    getBlock: ...;
                    getBlockByHeight: ...;
                    getHeight: ...;
                    getTx: ...;
                    getTxFee: ...;
                    getTxStatus: ...;
                    getUTXOs: ...;
                    issueTx: ...;
                },
            ) => client,
        ) => { [K in (...)
        | (...)
        | (...)]: (...)[(...)] }
      • getAllBalances: (args: GetAllBalancesParameters) => Promise<GetAllBalancesReturnType>

        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"]
        })
      • getAssetDescription: (args: GetAssetDescriptionParameters) => Promise<GetAssetDescriptionReturnType>
        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"
        })
      • getBalance: (args: GetBalanceParameters) => Promise<GetBalanceReturnType>

        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"
        })
      • getBlock: (args: GetBlockParameters) => Promise<XChainBlockType>
        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"
        })
      • getBlockByHeight: (args: GetBlockByHeightParameters) => Promise<XChainBlockType>
        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.getBlockByHeight({
        height: 1000001,
        encoding: "hex"
        })
      • getHeight: () => Promise<GetHeightReturnType>

        Get the height of the last accepted block.

        import { createAvalancheClient} from '@avalanche-sdk/client'
        import { avalanche } from '@avalanche-sdk/client/chains'

        const client = createAvalancheClient({
        chain: avalanche,
        transport: {
        type: "http",
        },
        })

        const height = await client.xChain.getHeight()
      • getTx: (args: GetTxParameters) => Promise<XChainTransactionType>
        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"
        })
      • getTxFee: () => Promise<GetTxFeeReturnType>

        Get the transaction fee for this node.

        import { createAvalancheClient} from '@avalanche-sdk/client'
        import { avalanche } from '@avalanche-sdk/client/chains'

        const client = createAvalancheClient({
        chain: avalanche,
        transport: {
        type: "http",
        },
        })

        const txFee = await client.xChain.getTxFee()
      • getTxStatus: (args: GetTxStatusParameters) => Promise<GetTxStatusReturnType>
        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"
        })
      • getUTXOs: (args: GetUTXOsParameters) => Promise<GetUTXOsReturnType>
        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"
        })
      • issueTx: (args: IssueTxParameters) => Promise<IssueTxReturnType>

        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...' })