A Avalanche Wallet Client. AvalancheWalletClient
Get the base fee for the next block.
Get the fee config for a specific block.
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()
Get the active rules at a specific timestamp.
Get the chain configuration for the C-Chain.
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));
Get the priority fee needed to be included in a block.
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",
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({
...
})
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..."
})
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({
...
\ * })
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"
})
OptionalxpAccount?: LocalXPAccount
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.