Avalanche SDK Client
    Preparing search index...

    Function createAvalancheWalletClient

    • Creates an Avalanche Wallet Client with a given transport configured for a Chain.

      The Avalanche Wallet Client is an interface to interact with the Core Wallet API through Avalanche-specific JSON-RPC API methods.

      Type Parameters

      • transport extends Transport = Transport
      • chain extends undefined | Chain = undefined | Chain
      • account extends undefined | Account = undefined
      • rpcSchema extends undefined | RpcSchema = undefined

      Parameters

      Returns {
          baseFee: () => Promise<string>;
          cChain: AvalancheWalletCoreClient<transport, chain, account, rpcSchema extends RpcSchema ? [...(...)[], ...(...)[]] : (...)[], CChainWalletActions & CChainActions>;
          cChainClient: { extend: <const client extends { [key: ...]: ... }>(fn: (client: ...) => ...) => { [K in (...)]: (...) } };
          feeConfig: (args: FeeConfigParameters) => Promise<FeeConfigReturnType>;
          getAccountPubKey: () => Promise<GetAccountPubKeyReturnType>;
          getActiveRulesAt: (args: GetActiveRulesAtParameters) => Promise<GetActiveRulesAtReturnType>;
          getChainConfig: () => Promise<GetChainConfigReturnType>;
          getRegistrationJustification: (args: GetRegistrationJustificationParams) => Promise<GetRegistrationJustificationReturnType>;
          maxPriorityFeePerGas: () => Promise<string>;
          pChain: AvalancheWalletCoreClient<transport, chain, account, rpcSchema extends RpcSchema ? [...(...)[], ...(...)[]] : (...)[], PChainWalletActions & PChainActions>;
          pChainClient: { extend: <const client extends { [key: ...]: ... }>(fn: (client: ...) => ...) => { [K in (...)]: (...) } };
          send: (args: SendParameters) => Promise<SendReturnType>;
          sendXPTransaction: (args: SendXPTransactionParameters) => Promise<SendXPTransactionReturnType>;
          signXPMessage: (args: SignXPMessageParameters) => Promise<SignXPMessageReturnType>;
          signXPTransaction: (args: SignXPTransactionParameters) => Promise<SignXPTransactionReturnType>;
          waitForTxn: (args: WaitForTxnParameters) => Promise<void>;
          xChain: AvalancheWalletCoreClient<transport, chain, account, rpcSchema extends RpcSchema ? [...(...)[], ...(...)[]] : (...)[], XChainWalletActions & XChainActions>;
          xChainClient: { extend: <const client extends { [key: ...]: ... }>(fn: (client: ...) => ...) => { [K in (...)]: (...) } };
          xpAccount?: LocalXPAccount;
      }

      A Avalanche Wallet Client. AvalancheWalletClient

      • baseFee: () => Promise<string>
        import { createAvalancheClient} from '@avalanche-sdk/client'
        import { avalanche } from '@avalanche-sdk/client/chains'

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

        const baseFee = await client.baseFee()
      • cChain: AvalancheWalletCoreClient<transport, chain, account, rpcSchema extends RpcSchema ? [...(...)[], ...(...)[]] : (...)[], CChainWalletActions & CChainActions>
      • cChainClient: { extend: <const client extends { [key: ...]: ... }>(fn: (client: ...) => ...) => { [K in (...)]: (...) } }
      • feeConfig: (args: FeeConfigParameters) => Promise<FeeConfigReturnType>

        Get the fee config for a specific block.

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

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

        const feeConfig = await client.feeConfig({ blk: "0x1" })
      • getAccountPubKey: () => Promise<GetAccountPubKeyReturnType>

        Gets the public key associated with the wallet account.

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

        // You can pass a local account otherwise a custom provider can be used
        const account = privateKeyToAvalancheAccount("0x...")
        const walletClient = createAvalancheWalletClient({
        account,
        chain: avalanche,
        transport: { type: "http" },
        })

        const pubKey = await walletClient.getAccountPubKey()

        // Or you can use a custom provider (e.g. window.avalanche, window.ethereum, etc.)
        const walletClient = createAvalancheWalletClient({
        chain: avalanche,
        transport: { type: "custom", provider: window.avalanche! },
        })

        const pubKey = await walletClient.getAccountPubKey()
      • getActiveRulesAt: (args: GetActiveRulesAtParameters) => Promise<GetActiveRulesAtReturnType>

        Get the active rules at a specific timestamp.

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

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

        const activeRules = await client.getActiveRulesAt({ timestamp: "0x1" })
      • getChainConfig: () => Promise<GetChainConfigReturnType>

        Get the chain configuration for the C-Chain.

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

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

        const chainConfig = await client.getChainConfig()
      • getRegistrationJustification: (args: GetRegistrationJustificationParams) => Promise<GetRegistrationJustificationReturnType>

        Retrieves the registration justification for the given validation ID Hex and subnet ID.

        If the validation ID corresponds to a bootstrap validator, the justification bytes produced by ConvertSubnetToL1Tx are returned.

        Otherwise, the function searches the Warp logs on the chain where the validator manager is deployed to locate the RegisterL1ValidatorMessage for the specified validation ID.

        import { createAvalancheClient } from "@avalanche-sdk/client";
        import { getRegistrationJustification } from "@avalanche-sdk/client/methods/public";
        import { defineChain } from "@avalanche-sdk/client/chains";
        import { utils } from "@avalanche-sdk/client/utils";

        const chainConfig = defineChain({
        id: 28098,
        name: "Rough Complexity Chain",
        rpcUrls: {
        default: {
        http: [
        "https://base-url-to-your-rpc/ext/bc/28zXo5erueBemgxPjLom6Vhsm6oVyftLtfQSt61fd62SghoXrz/rpc",
        ],
        },
        },
        });

        const publicClient = createAvalancheClient({
        chain: chainConfig,
        transport: {
        type: "http",
        },
        });

        const validationIDHex = utils.bufferToHex(
        utils.base58check.decode(
        "TEwxg8JzAUsqFibtYkaiiYH9G1h5ZfX56zYURXpyaPRCSppC4"
        )
        );

        const justification = await publicClient.getRegistrationJustification({
        validationIDHex,
        subnetIDStr: "2DN6PTi2uXNCzzNz1p2ckGcW2eqTfpt2kv2a1h7EV36hYV3XRJ",
        maxBootstrapValidators: 200,
        chunkSize: 200,
        maxChunks: 100,
        });

        console.log("justification", JSON.stringify(justification, null, 2));
      • maxPriorityFeePerGas: () => Promise<string>

        Get the priority fee needed to be included in a block.

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

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

        const maxPriorityFee = await client.maxPriorityFeePerGas()
      • pChain: AvalancheWalletCoreClient<transport, chain, account, rpcSchema extends RpcSchema ? [...(...)[], ...(...)[]] : (...)[], PChainWalletActions & PChainActions>
      • pChainClient: { extend: <const client extends { [key: ...]: ... }>(fn: (client: ...) => ...) => { [K in (...)]: (...) } }
      • send: (args: SendParameters) => Promise<SendReturnType>

        Sends tokens from the source chain to the destination chain.

        import { createAvalancheWalletClient } from '@avalanche-sdk/client'
        import { avalanche } from '@avalanche-sdk/client/chains'
        import { avaxToWei } from '@avalanche-sdk/client/utils'

        const walletClient = createAvalancheWalletClient({
        chain: avalanche,
        transport: { type: "http" },
        })

        const result = await walletClient.send({
        amount: avaxToWei(1), // 1 AVAX = 1_000_000_000_000_000_000 wei
        to: "0x0000000000000000000000000000000000000000",
      • sendXPTransaction: (args: SendXPTransactionParameters) => Promise<SendXPTransactionReturnType>

        Sends an P-Chain or X-Chain or C-Chain Atomic transaction to the network.

        import { createAvalancheWalletClient } from '@avalanche-sdk/client'
        import { avalanche } from '@avalanche-sdk/client/chains'
        import "@avalanche-sdk/client/window"

        // You can pass a local account otherwise a custom provider can be used
        const account = privateKeyToAvalancheAccount("0x...")
        const walletClient = createAvalancheWalletClient({
        account,
        chain: avalanche,
        transport: { type: "http" },
        })

        const result = await walletClient.sendXPTransaction({
        ...
        })

        // Or you can use a custom provider (e.g. window.avalanche, window.ethereum, etc.)
        const walletClient = createAvalancheWalletClient({
        chain: avalanche,
        transport: { type: "custom", provider: window.avalanche! },
        })

        const result = await walletClient.sendXPTransaction({
        ...
        })
      • signXPMessage: (args: SignXPMessageParameters) => Promise<SignXPMessageReturnType>

        Signs a message using the wallet's private key.

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

        // You can pass a local account otherwise a custom provider can be used
        const account = privateKeyToAvalancheAccount("0x...")
        const walletClient = createAvalancheWalletClient({
        account,
        chain: avalanche,
        transport: { type: "http" },
        })

        const signedMessage = await walletClient.signXPMessage({
        message: "Hello Avalanche",
        address: "X-avax1..."
        })

        // Or you can use a custom provider (e.g. window.avalanche, window.ethereum, etc.)
        const walletClient = createAvalancheWalletClient({
        chain: avalanche,
        transport: { type: "custom", provider: window.avalanche! },
        })

        const signedMessage = await walletClient.signXPMessage({
        message: "Hello Avalanche",
        address: "X-avax1..."
        })
      • signXPTransaction: (args: SignXPTransactionParameters) => Promise<SignXPTransactionReturnType>

        Signs an XP transaction using the wallet's private key.

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

        // You can pass a local account otherwise a custom provider can be used
        const account = privateKeyToAvalancheAccount("0x...")
        const walletClient = createAvalancheWalletClient({
        account,
        chain: avalanche,
        transport: { type: "http" },
        })

        const signedTx = await walletClient.signXPTransaction({
        ...
        })

        // Or you can use a custom provider (e.g. window.avalanche, window.ethereum, etc.)
        const walletClient = createAvalancheWalletClient({
        chain: avalanche,
        transport: { type: "custom", provider: window.avalanche! },
        })

        const signedTx = await walletClient.signXPTransaction({
        ...
        \ * })
      • waitForTxn: (args: WaitForTxnParameters) => Promise<void>

        Waits for a transaction to be confirmed on the network.

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

        const walletClient = createAvalancheWalletClient({
        chain: avalanche,
        transport: { type: "http" },
        })

        const result = await walletClient.waitForTxn({
        txID: "0x...",
        chainAlias: "P"
        })
      • xChain: AvalancheWalletCoreClient<transport, chain, account, rpcSchema extends RpcSchema ? [...(...)[], ...(...)[]] : (...)[], XChainWalletActions & XChainActions>
      • xChainClient: { extend: <const client extends { [key: ...]: ... }>(fn: (client: ...) => ...) => { [K in (...)]: (...) } }
      • OptionalxpAccount?: LocalXPAccount
      import { createAvalancheWalletClient } from '@avalanche-sdk/client'
      import { avalanche } from '@avalanche-sdk/client/chains'

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

      const pubKey = await client.getAccountPubKey()