Transferring funds between P-Chain using Avalanche CLI.
Transferring funds between P-Chain wallets becomes necessary in certain situations:
Funds need to be sent to the Avalanche L1 control key, which might have a zero balance due to fee payments. The Avalanche L1 control key requires funding to ensure proper support for Avalanche L1 operations.
Funds need to be moved from one Ledger address index to another. A Ledger manages an infinite sequence of addresses all derived from a master private key and can sign for any of those addresses. Each one is referred to by an index, or the associated address. Avalanche-CLI usually expects to use index 0, but sometimes, the funds are in a different index. Occasionally, a transfer made to a ledger can be made to an address different from the default one used by the CLI.
To enable direct transfers between P-Chain addresses, use the command avalanche key transfer. This operation involves a series of import/export actions with the P-Chain and X-Chain. The fee for this operation is four times the typical import operation fee, which comes out to 0.004 AVAX. You can find more information about fees here.
Note
The key transfer command can also be applied to the stored keys managed by the CLI. It enables moving funds from one stored key to another, and from a ledger to a stored key or the other way.
This how-to guide focuses on transferring funds between ledger accounts.
A ledger can manage an infinite amount of addresses derived from a main private key. Because of this, many operations require the user to specify an address index.
After confirming with a web wallet that 4.5 AVAX is available on p-chain address P-avax10an3cucdfqru984pnvv6y0rspvvclz63e523m0, connect ledger A.
With the avalanche app running, execute:
To see p-chain addresses and balances for the first 6 indices in the ledger derived owner addresses.
The address P-avax10an3cucdfqru984pnvv6y0rspvvclz63e523m0 has 4.5 AVAX and is associated with index 2 of ledger A.
A P-Chain to P-chain transfer is a two-part operation. There is no need for the two parts to be executed on the same machine, only for them to have some common params. For each part, the appropriate ledger (either source or target) must be connected to the machine executing it.
The first step moves the money out of the source account into a X-Chain account owner by the receiver. It needs to be signed by the sending ledger.
Enter the amount of AVAX to send to the recipient. This amount does not include fees.
Note that the sending ledger pays all the fees.
Then start the command:
First step is to specify the network. Mainnet in this case:
Next, the step of the transfer must be specified. Send in this case:
Next, the key source for the sender address. That is, the key that is going to sign the sending transactions. Select Use ledger:
Next, the ledger index is asked for. Input 2:
Next, the amount to be sent is asked for:
The, the target address is required:
After that, a confirmation message is printed. Read carefully and choose Yes:
In this step, Ledger B signs the transaction to receive the funds. It imports the funds on the X-Chain before exporting them back to the desired P-Chain address.
Connect ledger B and execute avalanche app.
Then start the command:
Specify the Mainnet network:
Next, the step of the transfer must be specified. Receive in this case:
Then, select Ledger as the key source that is going to sign the receiver operations.
Next, the ledger index is asked for. Input 0:
Next, the amount to receive is asked for:
After that, a confirmation message is printed. Select Yes:
Finally, the second part of the operation is executed and the transfer is completed.
As a multi step operation, the receiving part of the transfer can have intermediate errors, due for example to temporal network connections on the client side.
The CLI is going to capture errors and provide the user with a recovery message of the kind:
If this happen, the receiving operation should be started the same way, choosing the same options, but adding the extra suggested parameter:
Then, the CLI is going to resume where it left off.