If you're developing on the Avalanche network, automating AVAX transfers between chains can streamline your application's functionality. This guide details how to programmatically transfer tokens from the P-Chain to the C-Chain using API calls to an AvalancheGo node.
Prerequisites
- Access to an AvalancheGo node (local or remote)
- AVAX tokens on the P-Chain
- User credentials stored in the node's keystore (creation guide)
Cross-Chain Transfer Overview
Cross-chain transfers involve two steps:
- Exporting AVAX from the source chain (P-Chain)
- Importing AVAX to the destination chain (C-Chain)
Setting Up C-Chain Address and Key
The P-Chain uses Bech32 addresses, while the C-Chain uses hex-encoded EVM addresses. To bridge these formats:
Export a private key from the X-Chain (compatible with P-Chain):
{ "address": "X-avax1...", "privateKey": "PrivateKey-..." }Import the key to the C-Chain:
{ "address": "0x..." }
This links your P-Chain and C-Chain assets under a single control key.
Step-by-Step Transfer Process
1. Export AVAX from P-Chain
Call platform.exportAVAX with your C-Chain EVM address:
{
"to": "C-avax1...",
"amount": "1000000000" // 1 AVAX
}2. Import AVAX to C-Chain
Use avax.importAVAX to finalize the transfer:
{
"to": "0x...",
"txID": "2Q..."
}Note: No transaction fees apply for C-Chain imports.
Reversing the Flow: C-Chain to P-Chain
Export AVAX from C-Chain:
{ "to": "P-avax1...", "amount": "1000000000" }Import AVAX to P-Chain:
{ "txID": "2Q..." }
FAQs
Why can’t I directly convert P-Chain and C-Chain addresses?
The address formats derive from different cryptographic methods (Bech32 vs. EVM). Exporting/importing private keys bridges this gap.
Are there fees for cross-chain transfers?
- Export transactions incur standard fees.
- C-Chain imports are fee-free.
How long do transfers take?
Transfers typically complete within seconds, depending on network congestion.
Conclusion
By leveraging AvalancheGo APIs, you can seamlessly transfer AVAX between the P-Chain and C-Chain. This enables advanced use cases like smart contract interactions or staking automation.
👉 Explore advanced Avalanche integrations to enhance your blockchain projects.
For further questions, consult Avalanche’s developer documentation or community forums.