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

P-Chain Wallet Methods

Complete reference for P-Chain transaction preparation methods

Overview

The P-Chain Wallet Methods provide transaction preparation capabilities for the Platform Chain. These methods allow you to create unsigned transactions for various operations including base transfers, validator operations, delegator operations, subnet management, and cross-chain transfers.

Access: walletClient.pChain

prepareBaseTxn

Prepare a base P-Chain transaction for transferring AVAX.

Function Signature:

function prepareBaseTxn(
  params: PrepareBaseTxnParameters
): Promise<PrepareBaseTxnReturnType>;

interface PrepareBaseTxnParameters {
  outputs?: Output[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface Output {
  addresses: string[];
  amount: bigint;
  assetId?: string;
  locktime?: bigint;
  threshold?: number;
}

interface PrepareBaseTxnReturnType {
  tx: UnsignedTx;
  baseTx: BaseTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
outputsOutput[]NoArray of outputs to send funds to
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Output Object:

NameTypeRequiredDescription
addressesstring[]YesAddresses who can sign the consuming of this UTXO
amountbigintYesAmount in nano AVAX
assetIdstringNoAsset ID of the UTXO
locktimebigintNoTimestamp in seconds after which this UTXO can be consumed
thresholdnumberNoThreshold of addresses' signatures required to consume this UTXO

Returns:

TypeDescription
PrepareBaseTxnReturnTypeBase transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
baseTxBaseTxThe base transaction instance
chainAlias"P"The chain alias

Example:

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

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

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

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

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

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

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

Related:


prepareAddPermissionlessValidatorTxn

Prepare a transaction to add a permissionless validator to the Primary Network.

Function Signature:

function prepareAddPermissionlessValidatorTxn(
  params: PrepareAddPermissionlessValidatorTxnParameters
): Promise<PrepareAddPermissionlessValidatorTxnReturnType>;

interface PrepareAddPermissionlessValidatorTxnParameters {
  nodeId: string;
  stakeInAvax: bigint;
  end: bigint;
  rewardAddresses: string[];
  delegatorRewardAddresses: string[];
  delegatorRewardPercentage: number;
  publicKey?: string;
  signature?: string;
  threshold?: number;
  locktime?: bigint;
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareAddPermissionlessValidatorTxnReturnType {
  tx: UnsignedTx;
  addPermissionlessValidatorTx: AddPermissionlessValidatorTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
nodeIdstringYesNode ID of the validator being added
stakeInAvaxbigintYesAmount of AVAX to stake (in nano AVAX)
endbigintYesUnix time in seconds when validator will be removed
rewardAddressesstring[]YesAddresses which will receive validator rewards
delegatorRewardAddressesstring[]YesAddresses which will receive delegator fee rewards
delegatorRewardPercentagenumberYesPercentage of delegator rewards as delegation fee (2-100, up to 3 decimal places)
publicKeystringNoBLS public key (in hex format)
signaturestringNoBLS signature (in hex format)
thresholdnumberNoNumber of signatures required to spend reward UTXO (default: 1)
locktimebigintNoUnix timestamp after which reward UTXO can be spent (default: 0)
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareAddPermissionlessValidatorTxnReturnTypeAdd validator transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
addPermissionlessValidatorTxAddPermissionlessValidatorTxThe add validator transaction instance
chainAlias"P"The chain alias

Example:

import { avaxToNanoAvax } from "@avalanche-sdk/client/utils";

const validatorTx =
  await walletClient.pChain.prepareAddPermissionlessValidatorTxn({
    nodeId: "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg",
    stakeInAvax: avaxToNanoAvax(2000),
    end: BigInt(1716441600),
    rewardAddresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
    delegatorRewardAddresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
    delegatorRewardPercentage: 2.5,
    threshold: 1,
  });

// Sign and send
const signedTx = await walletClient.signXPTransaction({
  tx: validatorTx.tx,
  chainAlias: "P",
});

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

Related:


prepareAddPermissionlessDelegatorTxn

Prepare a transaction to add a permissionless delegator to a validator.

Function Signature:

function prepareAddPermissionlessDelegatorTxn(
  params: PrepareAddPermissionlessDelegatorTxnParameters
): Promise<PrepareAddPermissionlessDelegatorTxnReturnType>;

interface PrepareAddPermissionlessDelegatorTxnParameters {
  nodeId: string;
  stakeInAvax: bigint;
  end: bigint;
  rewardAddresses: string[];
  threshold?: number;
  locktime?: bigint;
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareAddPermissionlessDelegatorTxnReturnType {
  tx: UnsignedTx;
  addPermissionlessDelegatorTx: AddPermissionlessDelegatorTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
nodeIdstringYesNode ID of the validator to delegate to
stakeInAvaxbigintYesAmount of AVAX to stake (in nano AVAX)
endbigintYesUnix time in seconds when delegation stops
rewardAddressesstring[]YesAddresses which will receive rewards
thresholdnumberNoNumber of signatures required to spend reward UTXO (default: 1)
locktimebigintNoUnix timestamp after which reward UTXO can be spent (default: 0)
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareAddPermissionlessDelegatorTxnReturnTypeAdd delegator transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
addPermissionlessDelegatorTxAddPermissionlessDelegatorTxThe add delegator transaction instance
chainAlias"P"The chain alias

Example:

const delegatorTx =
  await walletClient.pChain.prepareAddPermissionlessDelegatorTxn({
    nodeId: "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg",
    stakeInAvax: avaxToNanoAvax(25),
    end: BigInt(1716441600),
    rewardAddresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
    threshold: 1,
  });

Related:


prepareExportTxn

Prepare a transaction to export AVAX from P-Chain to another chain.

Function Signature:

function prepareExportTxn(
  params: PrepareExportTxnParameters
): Promise<PrepareExportTxnReturnType>;

interface PrepareExportTxnParameters {
  destinationChain: "X" | "C";
  exportedOutputs: Output[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareExportTxnReturnType {
  tx: UnsignedTx;
  exportTx: ExportTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
destinationChain"X" | "C"YesChain alias to export funds to
exportedOutputsOutput[]YesOutputs to export
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareExportTxnReturnTypeExport transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
exportTxExportTxThe export transaction instance
chainAlias"P"The chain alias

Example:

const exportTx = await walletClient.pChain.prepareExportTxn({
  destinationChain: "C",
  exportedOutputs: [
    {
      addresses: [account.getEVMAddress()],
      amount: avaxToNanoAvax(0.001),
    },
  ],
});

// Sign and send
const signedTx = await walletClient.signXPTransaction({
  tx: exportTx.tx,
  chainAlias: "P",
});

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

Related:


prepareImportTxn

Prepare a transaction to import AVAX from another chain to P-Chain.

Function Signature:

function prepareImportTxn(
  params: PrepareImportTxnParameters
): Promise<PrepareImportTxnReturnType>;

interface PrepareImportTxnParameters {
  sourceChain: "X" | "C";
  importedOutput: ImportedOutput;
  fromAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface ImportedOutput {
  addresses: string[];
  locktime?: bigint;
  threshold?: number;
}

interface PrepareImportTxnReturnType {
  tx: UnsignedTx;
  importTx: ImportTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
sourceChain"X" | "C"YesChain alias to import funds from
importedOutputImportedOutputYesConsolidated imported output from atomic memory
fromAddressesstring[]NoAddresses to send funds from
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Imported Output Object:

NameTypeRequiredDescription
addressesstring[]YesAddresses who can sign the consuming of this UTXO
locktimebigintNoTimestamp in seconds after which this UTXO can be consumed
thresholdnumberNoNumber of signatures required out of total addresses to spend the imported output

Returns:

TypeDescription
PrepareImportTxnReturnTypeImport transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
importTxImportTxThe import transaction instance
chainAlias"P"The chain alias

Example:

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

// Sign and send
const signedTx = await walletClient.signXPTransaction({
  tx: importTx.tx,
  chainAlias: "P",
});

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

Related:


prepareAddSubnetValidatorTxn

Prepare a transaction to add a validator to a subnet.

Function Signature:

function prepareAddSubnetValidatorTxn(
  params: PrepareAddSubnetValidatorTxnParameters
): Promise<PrepareAddSubnetValidatorTxnReturnType>;

interface PrepareAddSubnetValidatorTxnParameters {
  subnetId: string;
  nodeId: string;
  weight: bigint;
  end: bigint;
  subnetAuth: readonly number[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareAddSubnetValidatorTxnReturnType {
  tx: UnsignedTx;
  addSubnetValidatorTx: AddSubnetValidatorTx;
  subnetOwners: PChainOwner;
  subnetAuth: number[];
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
subnetIdstringYesSubnet ID to add the validator to
nodeIdstringYesNode ID of the validator being added
weightbigintYesWeight of the validator used during consensus
endbigintYesEnd timestamp in seconds after which validator will be removed
subnetAuthreadonly number[]YesArray of indices from subnet's owners array who will sign this transaction
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareAddSubnetValidatorTxnReturnTypeAdd subnet validator transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
addSubnetValidatorTxAddSubnetValidatorTxThe add subnet validator transaction instance
subnetOwnersPChainOwnerThe subnet owners
subnetAuthnumber[]Array of indices from subnet's owners array
chainAlias"P"The chain alias

Example:

const addSubnetValidatorTx =
  await walletClient.pChain.prepareAddSubnetValidatorTxn({
    subnetId: "2b175hLJhGdj3CzgXNUHXDPVY3wQo3y3VWqPjKpF5vK",
    nodeId: "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg",
    weight: BigInt(1000000),
    end: BigInt(1716441600),
    subnetAuth: [0, 1],
  });

Related:


prepareRemoveSubnetValidatorTxn

Prepare a transaction to remove a validator from a subnet.

Function Signature:

function prepareRemoveSubnetValidatorTxn(
  params: PrepareRemoveSubnetValidatorTxnParameters
): Promise<PrepareRemoveSubnetValidatorTxnReturnType>;

interface PrepareRemoveSubnetValidatorTxnParameters {
  subnetId: string;
  nodeId: string;
  subnetAuth: readonly number[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareRemoveSubnetValidatorTxnReturnType {
  tx: UnsignedTx;
  removeSubnetValidatorTx: RemoveSubnetValidatorTx;
  subnetOwners: PChainOwner;
  subnetAuth: number[];
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
subnetIdstringYesSubnet ID to remove the validator from
nodeIdstringYesNode ID of the validator being removed
subnetAuthreadonly number[]YesArray of indices from subnet's owners array who will sign this transaction
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareRemoveSubnetValidatorTxnReturnTypeRemove subnet validator transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
removeSubnetValidatorTxRemoveSubnetValidatorTxThe remove subnet validator transaction instance
subnetOwnersPChainOwnerThe subnet owners
subnetAuthnumber[]Array of indices from subnet's owners array
chainAlias"P"The chain alias

Example:

const removeSubnetValidatorTx =
  await walletClient.pChain.prepareRemoveSubnetValidatorTxn({
    subnetId: "2b175hLJhGdj3CzgXNUHXDPVY3wQo3y3VWqPjKpF5vK",
    nodeId: "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg",
    subnetAuth: [0, 1],
  });

Related:


prepareCreateSubnetTxn

Prepare a transaction to create a new subnet.

Function Signature:

function prepareCreateSubnetTxn(
  params: PrepareCreateSubnetTxnParameters
): Promise<PrepareCreateSubnetTxnReturnType>;

interface PrepareCreateSubnetTxnParameters {
  subnetOwners: SubnetOwners;
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface SubnetOwners {
  addresses: string[];
  threshold?: number;
  locktime?: bigint;
}

interface PrepareCreateSubnetTxnReturnType {
  tx: UnsignedTx;
  createSubnetTx: CreateSubnetTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
subnetOwnersSubnetOwnersYesSubnet owners configuration
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Subnet Owners Object:

NameTypeRequiredDescription
addressesstring[]YesList of unique addresses (must be sorted lexicographically)
thresholdnumberNoNumber of unique signatures required to spend the output (must be ≤ length of addresses)
locktimebigintNoUnix timestamp after which the output can be spent

Returns:

TypeDescription
PrepareCreateSubnetTxnReturnTypeCreate subnet transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
createSubnetTxCreateSubnetTxThe create subnet transaction instance
chainAlias"P"The chain alias

Example:

const createSubnetTx = await walletClient.pChain.prepareCreateSubnetTxn({
  subnetOwners: {
    addresses: [
      "P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz",
      "P-fuji1y8zrxh9cvdny0e8n8n4n7h4q4h4q4h4q4h4q4h",
    ],
    threshold: 2,
  },
});

Related:


prepareCreateChainTxn

Prepare a transaction to create a new blockchain on a subnet.

Function Signature:

function prepareCreateChainTxn(
  params: PrepareCreateChainTxnParameters
): Promise<PrepareCreateChainTxnReturnType>;

interface PrepareCreateChainTxnParameters {
  subnetId: string;
  vmId: string;
  chainName: string;
  genesisData: Record<string, unknown>;
  subnetAuth: readonly number[];
  fxIds?: readonly string[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareCreateChainTxnReturnType {
  tx: UnsignedTx;
  createChainTx: CreateChainTx;
  subnetOwners: PChainOwner;
  subnetAuth: number[];
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
subnetIdstringYesSubnet ID to create the chain on
vmIdstringYesVM ID of the chain being created
chainNamestringYesName of the chain being created
genesisDataRecord<string, unknown>YesGenesis JSON data of the chain being created
subnetAuthreadonly number[]YesArray of indices from subnet's owners array who will sign this transaction
fxIdsreadonly string[]NoArray of FX IDs to be added to the chain
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareCreateChainTxnReturnTypeCreate chain transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
createChainTxCreateChainTxThe create chain transaction instance
subnetOwnersPChainOwnerThe subnet owners
subnetAuthnumber[]Array of indices from subnet's owners array
chainAlias"P"The chain alias

Example:

const createChainTx = await walletClient.pChain.prepareCreateChainTxn({
  subnetId: "2b175hLJhGdj3CzgXNUHXDPVY3wQo3y3VWqPjKpF5vK",
  vmId: "avm",
  chainName: "MyCustomChain",
  genesisData: {
    // Genesis configuration
  },
  subnetAuth: [0, 1],
});

Related:


prepareConvertSubnetToL1Txn

Prepare a transaction to convert a subnet to an L1 (Layer 1) blockchain.

Function Signature:

function prepareConvertSubnetToL1Txn(
  params: PrepareConvertSubnetToL1TxnParameters
): Promise<PrepareConvertSubnetToL1TxnReturnType>;

interface PrepareConvertSubnetToL1TxnParameters {
  subnetId: string;
  blockchainId: string;
  managerContractAddress: string;
  validators: L1Validator[];
  subnetAuth: readonly number[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface L1Validator {
  nodeId: string;
  nodePoP: {
    publicKey: string;
    proofOfPossession: string;
  };
  weight: bigint;
  initialBalanceInAvax: bigint;
  remainingBalanceOwner: PChainOwnerJSON;
  deactivationOwner: PChainOwnerJSON;
}

interface PrepareConvertSubnetToL1TxnReturnType {
  tx: UnsignedTx;
  convertSubnetToL1Tx: ConvertSubnetToL1Tx;
  subnetOwners: PChainOwner;
  subnetAuth: number[];
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
subnetIdstringYesSubnet ID of the subnet to convert
blockchainIdstringYesBlockchain ID of the L1 where validator manager contract is deployed
managerContractAddressstringYesAddress of the validator manager contract
validatorsL1Validator[]YesInitial set of L1 validators after conversion
subnetAuthreadonly number[]YesArray of indices from subnet's owners array who will sign this transaction
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

L1 Validator Object:

NameTypeDescription
nodeIdstringNode ID of the validator
nodePoP.publicKeystringPublic key of the validator
nodePoP.proofOfPossessionstringProof of possession of the public key
weightbigintWeight of the validator on the L1 used during consensus participation
initialBalanceInAvaxbigintInitial balance in nano AVAX required for paying contiguous fee
remainingBalanceOwnerPChainOwnerJSONOwner information for remaining balance if validator is removed/disabled
deactivationOwnerPChainOwnerJSONOwner information which can remove or disable the validator

Returns:

TypeDescription
PrepareConvertSubnetToL1TxnReturnTypeConvert subnet to L1 transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
convertSubnetToL1TxConvertSubnetToL1TxThe convert subnet to L1 transaction instance
subnetOwnersPChainOwnerThe subnet owners
subnetAuthnumber[]Array of indices from subnet's owners array
chainAlias"P"The chain alias

Example:

const convertSubnetToL1Tx =
  await walletClient.pChain.prepareConvertSubnetToL1Txn({
    subnetId: "2b175hLJhGdj3CzgXNUHXDPVY3wQo3y3VWqPjKpF5vK",
    blockchainId: "2oYMBNV4eNHyqk2fjjV5nVwDzxvbmovtDAOwPJCTc9wqg8k9t",
    managerContractAddress: "0x1234567890123456789012345678901234567890",
    validators: [
      {
        nodeId: "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg",
        nodePoP: {
          publicKey: "0x...",
          proofOfPossession: "0x...",
        },
        weight: BigInt(1000000),
        initialBalanceInAvax: avaxToNanoAvax(1000),
        remainingBalanceOwner: {
          addresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
          threshold: 1,
        },
        deactivationOwner: {
          addresses: ["P-fuji19fc97zn3mzmwr827j4d3n45refkksgms4y2yzz"],
          threshold: 1,
        },
      },
    ],
    subnetAuth: [0, 1],
  });

prepareRegisterL1ValidatorTxn

Prepare a transaction to register an L1 validator.

Function Signature:

function prepareRegisterL1ValidatorTxn(
  params: PrepareRegisterL1ValidatorTxnParameters
): Promise<PrepareRegisterL1ValidatorTxnReturnType>;

interface PrepareRegisterL1ValidatorTxnParameters {
  initialBalanceInAvax: bigint;
  blsSignature: string;
  message: string;
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareRegisterL1ValidatorTxnReturnType {
  tx: UnsignedTx;
  registerL1ValidatorTx: RegisterL1ValidatorTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
initialBalanceInAvaxbigintYesInitial balance in nano AVAX required for paying contiguous fee
blsSignaturestringYesBLS signature of the validator
messagestringYesSigned warp message hex with AddressedCall payload containing RegisterL1ValidatorMessage
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareRegisterL1ValidatorTxnReturnTypeRegister L1 validator transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
registerL1ValidatorTxRegisterL1ValidatorTxThe register L1 validator transaction instance
chainAlias"P"The chain alias

Example:

const registerL1ValidatorTx =
  await walletClient.pChain.prepareRegisterL1ValidatorTxn({
    initialBalanceInAvax: avaxToNanoAvax(1000),
    blsSignature: "0x...",
    message: "0x...",
  });

prepareDisableL1ValidatorTxn

Prepare a transaction to disable an L1 validator.

Function Signature:

function prepareDisableL1ValidatorTxn(
  params: PrepareDisableL1ValidatorTxnParameters
): Promise<PrepareDisableL1ValidatorTxnReturnType>;

interface PrepareDisableL1ValidatorTxnParameters {
  validationId: string;
  disableAuth: number[];
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareDisableL1ValidatorTxnReturnType {
  tx: UnsignedTx;
  disableL1ValidatorTx: DisableL1ValidatorTx;
  disableOwners: PChainOwner;
  disableAuth: number[];
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
validationIdstringYesValidation ID of the L1 validator
disableAuthnumber[]YesArray of indices from L1 validator's disable owners array who will sign this transaction
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareDisableL1ValidatorTxnReturnTypeDisable L1 validator transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
disableL1ValidatorTxDisableL1ValidatorTxThe disable L1 validator transaction instance
disableOwnersPChainOwnerThe disable owners
disableAuthnumber[]Array of indices from disable owners array
chainAlias"P"The chain alias

Example:

const disableL1ValidatorTx =
  await walletClient.pChain.prepareDisableL1ValidatorTxn({
    validationId: "0x...",
    disableAuth: [0, 1],
  });

prepareSetL1ValidatorWeightTxn

Prepare a transaction to set the weight of an L1 validator.

Function Signature:

function prepareSetL1ValidatorWeightTxn(
  params: PrepareSetL1ValidatorWeightTxnParameters
): Promise<PrepareSetL1ValidatorWeightTxnReturnType>;

interface PrepareSetL1ValidatorWeightTxnParameters {
  message: string;
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareSetL1ValidatorWeightTxnReturnType {
  tx: UnsignedTx;
  setL1ValidatorWeightTx: SetL1ValidatorWeightTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
messagestringYesSigned warp message hex with AddressedCall payload containing SetL1ValidatorWeightMessage
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareSetL1ValidatorWeightTxnReturnTypeSet L1 validator weight transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
setL1ValidatorWeightTxSetL1ValidatorWeightTxThe set L1 validator weight transaction instance
chainAlias"P"The chain alias

Example:

const setL1ValidatorWeightTx =
  await walletClient.pChain.prepareSetL1ValidatorWeightTxn({
    message: "0x...",
  });

prepareIncreaseL1ValidatorBalanceTxn

Prepare a transaction to increase the balance of an L1 validator.

Function Signature:

function prepareIncreaseL1ValidatorBalanceTxn(
  params: PrepareIncreaseL1ValidatorBalanceTxnParameters
): Promise<PrepareIncreaseL1ValidatorBalanceTxnReturnType>;

interface PrepareIncreaseL1ValidatorBalanceTxnParameters {
  balanceInAvax: bigint;
  validationId: string;
  fromAddresses?: string[];
  changeAddresses?: string[];
  utxos?: Utxo[];
  memo?: string;
  minIssuanceTime?: bigint;
  context?: Context;
}

interface PrepareIncreaseL1ValidatorBalanceTxnReturnType {
  tx: UnsignedTx;
  increaseL1ValidatorBalanceTx: IncreaseL1ValidatorBalanceTx;
  chainAlias: "P";
}

Parameters:

NameTypeRequiredDescription
balanceInAvaxbigintYesAmount of AVAX to increase the balance by (in nano AVAX)
validationIdstringYesValidation ID of the L1 validator
fromAddressesstring[]NoAddresses to send funds from
changeAddressesstring[]NoAddresses to receive change
utxosUtxo[]NoUTXOs to use as inputs
memostringNoTransaction memo
minIssuanceTimebigintNoEarliest time this transaction can be issued
contextContextNoTransaction context (auto-fetched if omitted)

Returns:

TypeDescription
PrepareIncreaseL1ValidatorBalanceTxnReturnTypeIncrease L1 validator balance transaction object

Return Object:

PropertyTypeDescription
txUnsignedTxThe unsigned transaction
increaseL1ValidatorBalanceTxIncreaseL1ValidatorBalanceTxThe increase L1 validator balance transaction instance
chainAlias"P"The chain alias

Example:

const increaseL1ValidatorBalanceTx =
  await walletClient.pChain.prepareIncreaseL1ValidatorBalanceTxn({
    balanceInAvax: avaxToNanoAvax(500),
    validationId: "0x...",
  });

Next Steps

Is this guide helpful?