Granite Upgrade Activates in06d:02h:04m:16s
MethodsWallet Methods

Wallet Methods

Complete reference for Avalanche wallet operations

Overview

The Avalanche Wallet Client provides methods for sending transactions, signing messages and transactions, and managing accounts across all Avalanche chains (P-Chain, X-Chain, and C-Chain). This reference covers all wallet-specific methods available through the Avalanche Wallet Client SDK.

Access: walletClient

send

Send tokens from the source chain to the destination chain. Automatically handles cross-chain transfers when needed.

Function Signature:

function send(params: SendParameters): Promise<SendReturnType>;

interface SendParameters {
  account?: AvalancheAccount;
  amount: bigint;
  to: Address | XPAddress;
  from?: Address | XPAddress;
  sourceChain?: "P" | "C";
  destinationChain?: "P" | "C";
  token?: "AVAX";
  context?: Context;
}

interface SendReturnType {
  txHashes: TransactionDetails[];
}

interface TransactionDetails {
  txHash: string;
  chainAlias: "P" | "C";
}

Parameters:

NameTypeRequiredDescription
accountAvalancheAccountNoAccount to send from (uses client account if omitted)
amountbigintYesAmount to send in wei
toAddress | XPAddressYesDestination address
fromAddress | XPAddressNoSource address (defaults to account address)
sourceChain"P" | "C"NoSource chain (default: "C")
destinationChain"P" | "C"NoDestination chain (default: "C")
token"AVAX"NoToken to send (only AVAX supported)
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
SendReturnTypeTransaction hashes object

Return Object:

PropertyTypeDescription
txHashesTransactionDetails[]Array of transaction details

Transaction Details Object:

PropertyTypeDescription
txHashstringThe hash of the transaction
chainAlias"P" | "C"The chain alias of the transaction

Example:

import { createAvalancheWalletClient } from "@avalanche-sdk/client";
import { privateKeyToAvalancheAccount } from "@avalanche-sdk/client/accounts";
import { avalanche } from "@avalanche-sdk/client/chains";
import { avaxToWei, avaxToNanoAvax } from "@avalanche-sdk/client/utils";

const account = privateKeyToAvalancheAccount("0x...");

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

// Send AVAX on C-Chain
const result = await walletClient.send({
  to: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
  amount: avaxToWei(0.001),
  destinationChain: "C",
});

console.log("Transaction hash:", result.txHashes[0].txHash);

// Send AVAX from C-Chain to P-Chain
const crossChainResult = await walletClient.send({
  to: "P-avax1example...",
  amount: avaxToWei(1),
  sourceChain: "C",
  destinationChain: "P",
});

console.log("Transfer transactions:", crossChainResult.txHashes);

Related:


getAccountPubKey

Get the public key associated with the wallet account in both EVM and XP formats.

Function Signature:

function getAccountPubKey(): Promise<GetAccountPubKeyReturnType>;

interface GetAccountPubKeyReturnType {
  evm: string;
  xp: string;
}

Returns:

TypeDescription
GetAccountPubKeyReturnTypePublic keys object

Return Object:

PropertyTypeDescription
evmstringPublic key in EVM format
xpstringPublic key in XP format

Example:

const pubKeys = await walletClient.getAccountPubKey();

console.log("EVM public key:", pubKeys.evm);
console.log("XP public key:", pubKeys.xp);

Related:


waitForTxn

Wait for a transaction to be confirmed on the network.

Function Signature:

function waitForTxn(params: WaitForTxnParameters): Promise<void>;

interface WaitForTxnParameters {
  txHash: string;
  chainAlias: "X" | "P" | "C";
  sleepTime?: number;
  maxRetries?: number;
}

Parameters:

NameTypeRequiredDescription
txHashstringYesTransaction hash
chainAlias"X" | "P" | "C"YesChain where transaction was submitted
sleepTimenumberNoTime to sleep between retries in milliseconds (default: 300)
maxRetriesnumberNoMaximum number of retries (default: 10)

Returns:

TypeDescription
Promise<void>Promise that resolves when transaction is confirmed or rejects if transaction fails

Example:

const txHash = "0x...";

try {
  await walletClient.waitForTxn({
    txHash,
    chainAlias: "C",
    sleepTime: 500, // Wait 500ms between checks
    maxRetries: 20, // Check up to 20 times
  });

  console.log("Transaction confirmed!");
} catch (error) {
  console.error("Transaction failed:", error);
}

Related:


sendXPTransaction

Send a signed XP transaction to the network (X-Chain, P-Chain, or C-Chain).

Function Signature:

function sendXPTransaction(
  params: SendXPTransactionParameters
): Promise<SendXPTransactionReturnType>;

interface SendXPTransactionParameters {
  account?: AvalancheAccount | Address;
  tx: string | UnsignedTx;
  chainAlias: "X" | "P" | "C";
  externalIndices?: number[];
  internalIndices?: number[];
  utxoIds?: string[];
  feeTolerance?: number;
  subnetAuth?: number[];
  subnetOwners?: PChainOwner;
  disableOwners?: PChainOwner;
  disableAuth?: number[];
}

interface SendXPTransactionReturnType {
  txHash: string;
  chainAlias: "X" | "P" | "C";
}

Parameters:

NameTypeRequiredDescription
accountAvalancheAccount | AddressNoAccount to use for the transaction
txstring | UnsignedTxYesTransaction to send (hex string or UnsignedTx object)
chainAlias"X" | "P" | "C"YesTarget chain
externalIndicesnumber[]NoExternal indices to use for the transaction
internalIndicesnumber[]NoInternal indices to use for the transaction
utxoIdsstring[]NoUTXO IDs to use for the transaction
feeTolerancenumberNoFee tolerance to use for the transaction
subnetAuthnumber[]NoSubnet auth to use for the transaction
subnetOwnersPChainOwnerNoSubnet owners to use for the transaction
disableOwnersPChainOwnerNoDisable owners to use for the transaction
disableAuthnumber[]NoDisable auth to use for the transaction

Returns:

TypeDescription
SendXPTransactionReturnTypeTransaction hash object

Return Object:

PropertyTypeDescription
txHashstringThe hash of the transaction
chainAlias"X" | "P" | "C"The chain alias

Example:

// This is typically used with prepare methods from chain-specific wallets
const unsignedTx = await walletClient.pChain.prepareBaseTxn({
  outputs: [
    {
      addresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
      amount: avaxToNanoAvax(1),
    },
  ],
});

const signedTx = await walletClient.signXPTransaction({
  tx: unsignedTx.tx,
  chainAlias: "P",
});

const { txHash } = await walletClient.sendXPTransaction({
  tx: signedTx.signedTxHex,
  chainAlias: "P",
});

console.log("Transaction hash:", txHash);

Related:


signXPTransaction

Sign an XP transaction (X-Chain, P-Chain, or C-Chain).

Function Signature:

function signXPTransaction(
  params: SignXPTransactionParameters
): Promise<SignXPTransactionReturnType>;

interface SignXPTransactionParameters {
  account?: AvalancheAccount | Address;
  tx?: string | UnsignedTx;
  signedTxHex?: string;
  chainAlias: "X" | "P" | "C";
  utxoIds?: string[];
  subnetAuth?: number[];
  subnetOwners?: PChainOwner;
  disableOwners?: PChainOwner;
  disableAuth?: number[];
  context?: Context;
}

interface Signatures {
  signature: string;
  sigIndices: number[];
}

interface SignXPTransactionReturnType {
  signedTxHex: string;
  signatures: Signatures[];
  chainAlias: "X" | "P" | "C";
  subnetAuth?: number[];
  subnetOwners?: PChainOwner;
  disableOwners?: PChainOwner;
  disableAuth?: number[];
}

Parameters:

NameTypeRequiredDescription
accountAvalancheAccount | AddressNoAccount to use for the transaction
txstring | UnsignedTxNoUnsigned transaction (either tx or signedTxHex must be provided)
signedTxHexstringNoPre-signed transaction bytes (either tx or signedTxHex must be provided)
chainAlias"X" | "P" | "C"YesTarget chain
utxoIdsstring[]NoUTXO IDs to use for the transaction
subnetAuthnumber[]NoSubnet auth to use for the transaction
subnetOwnersPChainOwnerNoSubnet owners to use for the transaction
disableOwnersPChainOwnerNoDisable owners to use for the transaction
disableAuthnumber[]NoDisable auth to use for the transaction
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
SignXPTransactionReturnTypeSigned transaction object

Return Object:

PropertyTypeDescription
signedTxHexstringThe signed transaction in hex format
signaturesSignatures[]Array of signatures for the transaction
chainAlias"X" | "P" | "C"The chain alias
subnetAuthnumber[]?Subnet auth used for the transaction
subnetOwnersPChainOwner?Subnet owners used for the transaction
disableOwnersPChainOwner?Disable owners used for the transaction
disableAuthnumber[]?Disable auth used for the transaction

Signatures Object:

PropertyTypeDescription
signaturestringThe signature of the transaction with the current account
sigIndicesnumber[]The indices of the signatures. Contains [inputIndex, signatureIndex] pair

Example:

const unsignedTx = await walletClient.pChain.prepareBaseTxn({
  outputs: [
    {
      addresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
      amount: avaxToNanoAvax(0.1),
    },
  ],
});

const signedTx = await walletClient.signXPTransaction({
  tx: unsignedTx.tx,
  chainAlias: "P",
});

// Now send the signed transaction
const { txHash } = await walletClient.sendXPTransaction({
  tx: signedTx.signedTxHex,
  chainAlias: "P",
});

console.log("Transaction hash:", txHash);

Related:


signXPMessage

Sign a message with an XP account (P-Chain or X-Chain addresses).

Function Signature:

function signXPMessage(
  params: SignXPMessageParameters
): Promise<SignXPMessageReturnType>;

interface SignXPMessageParameters {
  account?: AvalancheAccount | Address;
  message: string;
  accountIndex?: number;
}

interface SignXPMessageReturnType {
  signature: string;
}

Parameters:

NameTypeRequiredDescription
accountAvalancheAccount | AddressNoAccount to use for the message
messagestringYesMessage to sign
accountIndexnumberNoAccount index to use for the message from custom transport (e.g., core extension)

Returns:

TypeDescription
SignXPMessageReturnTypeMessage signature object

Return Object:

PropertyTypeDescription
signaturestringHex-encoded signature of the message

Example:

const { signature } = await walletClient.signXPMessage({
  message: "Hello Avalanche",
});

console.log("Signature:", signature);

Related:


EVM Transaction Methods

The Avalanche Wallet Client extends viem's Wallet Client, providing access to all standard Ethereum transaction methods.

Standard viem Methods

// Send transaction
const hash = await walletClient.sendTransaction({
  to: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
  value: parseEther("0.001"),
});

// Sign message
const signature = await walletClient.signMessage({
  message: "Hello World",
});

// Sign typed data (EIP-712)
const typedSignature = await walletClient.signTypedData({
  domain: { ... },
  types: { ... },
  primaryType: "Message",
  message: { ... },
});

For complete EVM wallet method reference, see: Viem Documentation


Chain-Specific Wallet Operations

P-Chain Wallet Operations

Access through walletClient.pChain:

// Prepare base transaction
const baseTx = await walletClient.pChain.prepareBaseTxn({
  outputs: [
    {
      addresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
      amount: avaxToNanoAvax(1),
    },
  ],
});

// Prepare export transaction
const exportTx = await walletClient.pChain.prepareExportTxn({
  destinationChain: "C",
  exportedOutputs: [
    {
      addresses: ["0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"],
      amount: avaxToNanoAvax(1),
    },
  ],
});

// Prepare import transaction
const importTx = await walletClient.pChain.prepareImportTxn({
  sourceChain: "C",
  importedOutput: {
    addresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
  },
});

See P-Chain Wallet Methods for complete reference.

X-Chain Wallet Operations

Access through walletClient.xChain:

// Prepare base transaction
const baseTx = await walletClient.xChain.prepareBaseTxn({
  outputs: [
    {
      addresses: ["X-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
      amount: avaxToNanoAvax(1),
    },
  ],
});

See X-Chain Wallet Methods for complete reference.

C-Chain Wallet Operations

Access through walletClient.cChain:

// Prepare export transaction
const exportTx = await walletClient.cChain.prepareExportTxn({
  destinationChain: "P",
  fromAddress: account.getEVMAddress(),
  exportedOutput: {
    addresses: [account.getXPAddress("P")],
    amount: avaxToNanoAvax(1),
  },
});

// Prepare import transaction
const importTx = await walletClient.cChain.prepareImportTxn({
  sourceChain: "P",
  toAddress: account.getEVMAddress(),
});

See C-Chain Wallet Methods for complete reference.


Next Steps

Is this guide helpful?