diff --git a/docs/dapps/smart-contracts/create-erc-20-token-on-avalanche-c-chain.md b/docs/dapps/smart-contracts/create-erc-20-token-on-avalanche-c-chain.md index 22951cb336e..86f4a487cc2 100644 --- a/docs/dapps/smart-contracts/create-erc-20-token-on-avalanche-c-chain.md +++ b/docs/dapps/smart-contracts/create-erc-20-token-on-avalanche-c-chain.md @@ -47,7 +47,7 @@ Depending on the network used, there are three ways to get funds to your C-Chain ### **Using Avalanche Wallet** -On the main net, you can use the [Avalanche Wallet](https://wallet.avax.network/) to transfer funds from the X-Chain to your C-Chain address. The process is simple, as explained in this [tutorial](.././../quickstart/transfer-avax-between-x-chain-and-c-chain.md). Wallet can be used on test and local networks, too. +On the main net, you can use the [Avalanche Wallet](https://wallet.avax.network/) to transfer funds from the X-Chain to your C-Chain address. The process is simple, as explained in this [tutorial](https://support.avax.network/en/articles/6169872-how-to-make-a-cross-chain-transfer-in-the-avalanche-wallet). Wallet can be used on test and local networks, too. ### **Using Test Network Faucet** diff --git a/docs/dapps/smart-contracts/deploy-a-smart-contract-on-avalanche-using-remix-and-metamask.md b/docs/dapps/smart-contracts/deploy-a-smart-contract-on-avalanche-using-remix-and-metamask.md index e0d2fa3dc2c..6cc4edd4794 100644 --- a/docs/dapps/smart-contracts/deploy-a-smart-contract-on-avalanche-using-remix-and-metamask.md +++ b/docs/dapps/smart-contracts/deploy-a-smart-contract-on-avalanche-using-remix-and-metamask.md @@ -47,7 +47,7 @@ Log in to MetaMask -> Click the Network drop-down -> Select Custom RPC ### **Using Avalanche Wallet** -On the main net, you can use the [Avalanche Wallet](https://wallet.avax.network/) to transfer funds from the X-Chain to your C-Chain address. The process is simple, as explained in this [tutorial](../../quickstart/transfer-avax-between-x-chain-and-c-chain.md). Wallet can be used on test and local networks, too. +On the main net, you can use the [Avalanche Wallet](https://wallet.avax.network/) to transfer funds from the X-Chain to your C-Chain address. The process is simple, as explained in this [tutorial](https://support.avax.network/en/articles/6169872-how-to-make-a-cross-chain-transfer-in-the-avalanche-wallet). Wallet can be used on test and local networks, too. ### **Using Test Network Faucet** diff --git a/docs/dapps/smart-contracts/using-truffle-with-the-avalanche-c-chain.md b/docs/dapps/smart-contracts/using-truffle-with-the-avalanche-c-chain.md index d504237b25f..553dc546520 100644 --- a/docs/dapps/smart-contracts/using-truffle-with-the-avalanche-c-chain.md +++ b/docs/dapps/smart-contracts/using-truffle-with-the-avalanche-c-chain.md @@ -6,7 +6,7 @@ ## Requirements -You've completed [Run an Avalanche Node](../../nodes/build/run-avalanche-node-manually.md) and are familiar with [Avalanche's architecture](../../overview/getting-started/avalanche-platform.md). You've also performed a cross-chain swap via the [Transfer AVAX Between X-Chain and C-Chain](.././../quickstart/transfer-avax-between-x-chain-and-c-chain.md) tutorial to get funds to your C-Chain address. +You've completed [Run an Avalanche Node](../../nodes/build/run-avalanche-node-manually.md) and are familiar with [Avalanche's architecture](../../overview/getting-started/avalanche-platform.md). You've also performed a cross-chain swap via this [this tutorial](https://support.avax.network/en/articles/6169872-how-to-make-a-cross-chain-transfer-in-the-avalanche-wallet) to get funds to your C-Chain address. ## Dependencies @@ -247,7 +247,7 @@ truffle(development)> await web3.eth.getBalance(accounts[1]); ### Fund your account -If you wish to fund accounts your own, follow the steps in the [Transfer AVAX Between X-Chain and C-Chain](../../quickstart/transfer-avax-between-x-chain-and-c-chain.md) tutorial. You'll need to send at least `135422040` nAVAX to the account to cover the cost of contract deployments. +If you wish to fund accounts your own, follow the steps in this [tutorial](https://support.avax.network/en/articles/6169872-how-to-make-a-cross-chain-transfer-in-the-avalanche-wallet). You'll need to send at least `135422040` nAVAX to the account to cover the cost of contract deployments. ### Personal APIs diff --git a/docs/quickstart/README.md b/docs/quickstart/README.md index a97f9722436..7f4ece7f173 100644 --- a/docs/quickstart/README.md +++ b/docs/quickstart/README.md @@ -5,9 +5,7 @@ | [**Create a Local Test Network**](create-a-local-test-network.md) | Create a local Avalanche test network. | | [**Fund a Local Test Network**](fund-a-local-test-network.md) | Fund an address on a local Avalanche test network. | | [**Fuji Workflow**](fuji-workflow.md) | Avalanche Fuji Workflow. | -| [**Transfer AVAX Between the X-Chain and C-Chain**](transfer-avax-between-x-chain-and-c-chain.md) | Send AVAX between the X-Chain and C-Chain | -| [**Transfer AVAX Between the X-Chain and P-Chain**](transfer-avax-between-x-chain-and-p-chain.md) | Send AVAX between the X-Chain and P-Chain | -| [**Transfer AVAX Between the P-Chain and C-Chain**](transfer-avax-between-p-chain-and-c-chain.md) | Send AVAX between the P-Chain and C-Chain | +| [**Transfers AVAX Tokens Between Chains**](cross-chain-transfers) | Send AVAX between Chains | | [**Multi Signature UTXOs with AvalancheJS**](multisig-utxos-with-avalanchejs.md) | Learn about creating and issuing multi signature UTXOs with AvalancheJS | | [**Avalanche Transaction Fee**](transaction-fees.md) | Avalanche Transaction Fee for all chains | | [**Adjusting Gas Price During High Network Activity**](adjusting-gas-price-during-high-network-activity.md) | Adjusting Gas Price During High Network Activity | diff --git a/docs/quickstart/cross-chain-transfers.md b/docs/quickstart/cross-chain-transfers.md new file mode 100644 index 00000000000..de1e9b63a41 --- /dev/null +++ b/docs/quickstart/cross-chain-transfers.md @@ -0,0 +1,291 @@ +# Transfer AVAX Tokens Between Chains + +## Introduction + +This article shows how to transfer AVAX tokens programmatically between any two chains (X/P/C chains) of the Primary Network. + +If you are looking for how to transfter AVAX tokens using the web wallet, please check out [this article](https://support.avax.network/en/articles/6169872-how-to-make-a-cross-chain-transfer-in-the-avalanche-wallet). + +## Prerequisites + +- You are familiar with [Avalanche's architecture](../overview/getting-started/avalanche-platform.md). +- You have completed [Run an Avalanche Node](../nodes/build/run-avalanche-node-manually.md). +- You are faimilar with [AvalancheJS](https://github.com/ava-labs/AvalancheJS). +- You have installed [ts-node](https://www.npmjs.com/package/ts-node#installation) so that you can follow examples in this tutorial. + +## Getting Started + +To use AvalancheJS, you can clone the repo: + +```zsh +$ git clone https://github.com/ava-labs/avalanchejs.git +``` + +or add it to an existing project: + +```zsh +$ yarn add --dev avalanche +``` + +For this tutorial we will use `ts-node` to run the example scripts directly from an AvalancheJS directory. + +In order to send AVAX, you need to have some AVAX. You can use a pre-funded account on local network or get testnet AVAX from the [Avalanche Faucet](https://faucet.avax.network), which is an easy way to get to play around with Avalanche. After getting comfortable with your code, you can run the code on Mainnet after making necessary changes. + +## Transferring AVAX using AvalancheJS + +The easiest way to transfer AVAX between chains is to use [AvalancheJS](https://github.com/ava-labs/AvalancheJS) which is a programmatic way to access and move AVAX. + +AvalancheJS allows you to create and sign transactions locally which is why it is the recommended way to transfer AVAX between chains. We are moving away from using AvalancheGo's keystore because it requires you to keep your keys on a full node which makes them a target for malicious hackers. + +### Example Code + +Following files can be found under the [examples](https://github.com/ava-labs/avalanchejs/tree/master/examples) directory of the AvalancheJS project. + +| Source Chain | Title | Path | +| :------------ | :---------------------------------------------------------------------------------------------------------------------------------------- | :------------------- | +| **_X-Chain_** | [**X-Chain : Export Avax to C-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildExportTx-cchain-avax.ts) | _X Chain >> C Chain_ | +| **_X-Chain_** | [**C-Chain : Import Avax from X-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/evm/buildImportTx-xchain.ts) | _X Chain >> C Chain_ | +| **_X-Chain_** | [**X-Chain : Export Avax to P-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildExportTx-PChain.ts) | _X Chain >> P Chain_ | +| **_X-Chain_** | [**P-Chain : Import Avax from X-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/platformvm/buildImportTx-XChain.ts) | _X Chain >> P Chain_ | +| **_P-Chain_** | [**P-Chain : Export Avax to X-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/platformvm/buildExportTx-XChain.ts) | _P Chain >> X Chain_ | +| **_P-Chain_** | [**X-Chain : Import Avax from P-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildImportTx-PChain.ts) | _P Chain >> X Chain_ | +| **_P-Chain_** | [**P-Chain : Export Avax to C-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/platformvm/buildExportTx-CChain.ts) | _P Chain >> C Chain_ | +| **_P-Chain_** | [**C-Chain : Import Avax from P-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/evm/buildImportTx-PChain.ts) | _P Chain >> C Chain_ | +| **_C-Chain_** | [**C-Chain : Export Avax to X-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/evm/buildExportTx-xchain-avax.ts) | _C Chain >> X Chain_ | +| **_C-Chain_** | [**X-Chain : Import Avax from C-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildImportTx-cchain.ts) | _C Chain >> X Chain_ | +| **_C-Chain_** | [**C-Chain : Export Avax to P-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/evm/buildExportTx-pchain.ts) | _C Chain >> P Chain_ | +| **_C-Chain_** | [**P-Chain : Import Avax from C-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/platformvm/buildImportTx-CChain.ts) | _C Chain >> P Chain_ | + +:::tip + +The naming convention in the file and directory names are: + +AVM is for X-Chaim, EVM for C-Chain, and PlatformVM for P-Chain. + +::: + +### Transaction Fee + +Transaction fees are fixed on X-Chain and P-Chain, while dynamic on C-Chain, see [this article](./transaction-fees.md#fee-schedule) for details. When transfering tokens, please take fee into consideration in calculating total amount to be transferred. + +## Fuji Workflow + +This tutorial uses [**X-Chain <-> C-Chain**](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildExportTx-cchain-avax.ts) transfers as an example. Transferring between other chains are very similar. + +### Transfer from the X-Chain to the C-Chain + +To transfer a specified amount token from X-Chain to C-Chain, the token needs to be first exported from the X-Chain, then imported to C-Chain. + +#### Export the Avax Token From X-Chain to C-Chain + +Select the [**`examples/avm`**](https://github.com/ava-labs/avalanchejs/tree/master/examples/avm) folder to view the AvalancheJS X-Chain examples. To export AVAX from the X-Chain to the C-Chain, select [`avm/buildExportTx-cchain-avax.ts`](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildExportTx-cchain-avax.ts). + +##### Private Key + +Locate this line in the file + +```js +const privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}`; +``` + +and replace this with a private key that you control. + +```js +const privKey: string = ""; +``` + +##### Network Setting + +The following settings work when using a local node started with [`--network-id=fuji`](../nodes/maintain/avalanchego-config-flags.md#network-id): + +```js +const ip: string = "localhost"; +const port: number = 9650; +const protocol: string = "http"; +const networkID: number = 5; +``` + +However, to connect directly to the [Avalanche Fuji Testnet API server](../apis/avalanchego/public-api-server.md), the following changes are needed: + +```js +const ip: string = "api.avax-test.network"; +const port: number = 443; +const protocol: string = "https"; +const networkID: number = 5; +``` + +Depending on the networkID passed in when instantiating Avalanche, the encoded addresses used will have a distinctive Human Readable Part(HRP) per each network. + +_Example Address: 5 - X-`fuji`19rknw8l0grnfunjrzwxlxync6zrlu33yxqzg0h_ + +For Fuji Testnet, 5 is the correct value to use. + +```js +const networkID: number = 5; +``` + +To learn more about encoded addresses, click [here](../apis/avalanchejs/manage-x-chain-keys.md#encode-bech32-addresses). + +**Set the Correct Amount To Send:** + +By default the scripts send the wallet's entire AVAX balance: + +```js +const balance: BN = new BN(getBalanceResponse.balance); +const amount: BN = balance.sub(fee); +``` + +To send a different amount, please replace the code above with the following. Below sets a new value of 0.01 AVAX (`10000000` GWEI). Value is set in GWEI format where `1,000,000,000` GWEI = 1 AVAX + +```js +const value: BN = new BN("10000000"); +const amount: BN = value.sub(fee); +``` + +:::tip +Snowtrace provides a [unit converter](https://snowtrace.io/unitconverter) between different units +::: + +Run the export script: + +```sh +$ ts-node examples/avm/buildExportTx-cchain-avax.ts +``` + +This returns: + +```sh +Success! TXID: 2uQvMcPZjmPXAyvz9cdKBphDDSmnxxx3vsUrxqpj3U92hsfQcc +``` + +#### Verify the Transaction + +You can now pass this txID `2uQvMcPZjmPXAyvz9cdKBphDDSmnxxx3vsUrxqpj3U92hsfQcc` into [examples/avm/getTx.ts](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/getTx.ts), plus other similar network settings, then you can run + +```zsh +$ ts-node examples/avm/getTx.ts +``` + +which returns: + +```js +{ + unsignedTx: { + networkID: 5, + blockchainID: '2JVSBoinj9C2J33VntvzYtVJNZdN2NKiwwKjcumHUWEb5DbBrm', + outputs: [ [Object] ], + inputs: [ [Object], [Object] ], + memo: '0x41564d207574696c697479206d6574686f64206275696c644578706f7274547820746f206578706f7274204156415820746f2074686520432d436861696e2066726f6d2074686520582d436861696e', + destinationChain: 'yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp', + exportedOutputs: [ [Object] ] + }, + credentials: [ + { + fxID: 'spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ', + credential: [Object] + }, + { + fxID: 'spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ', + credential: [Object] + } + ] +} +``` + +#### Import the Avax Token From X-Chain to C-Chain + +Select the [**`examples/evm`**](https://github.com/ava-labs/avalanchejs/tree/master/examples/evm) folder to view the AvalancheJS C-Chain examples. To import AVAX to the C-Chain from the X-Chain, select [`evm/buildImportTx-xchain.ts`](https://github.com/ava-labs/avalanchejs/blob/master/examples/evm/buildImportTx-xchain.ts) + +Copy the [network setting from above](#network-setting) into `evm/buildImportTx-xchain.ts`. + +Navigate to this part of the code and ensure that the `cHexAddress`(_Your C-Chain wallet address_) and `private key` are correct: + +```ts +const cHexAddress: string = ""; +const privKey: string = ""; +``` + +Run the import script: + +```sh +$ ts-node examples/evm/buildImportTx-xchain.ts +``` + +This returns: + +```sh +Success! TXID: 2uQvMcPZjmPXAyvz9cdKBphDDSmnxxx3vsUrxqpj3U92hsfQcc +``` + +That's it! You've transferred AVAX from the X-Chain to C-Chain! + +You can verify this TX by copy / pasting the import TXID into [Avascan](https://testnet.avascan.info/blockchain/c/tx/2uQvMcPZjmPXAyvz9cdKBphDDSmnxxx3vsUrxqpj3U92hsfQcc). + +### Transfer from the C-Chain to the X-Chain + +To return the AVAX back to the X-Chain, you need to do the transfer in the opposite direction. + +#### Export the Avax Token From C-Chain to X-Chain + +Select the [**`examples/evm`**](https://github.com/ava-labs/avalanchejs/tree/master/examples/evm) folder to view the AvalancheJS C-Chain examples. To export AVAX from the X-Chain to the C-Chain, select [`evm/buildExportTx-xchain-avax.ts`](https://github.com/ava-labs/avalanchejs/blob/master/examples/evm/buildExportTx-xchain-avax.ts). + +Make necessary changes as above for private key and network settings. + +You can change the amount of AVAX to send by editing the _BN_ variable: `avaxAmount`. The sample code assigns this as `1e7` or `10000000` (0.01 AVAX) + +The fee here will only be for exporting the asset. The import fees will be deducted from the UTXOs present on the Exported Atomic Memory, a memory location where UTXOs stay after getting exported but before being imported. + +```ts +let avaxAmount: BN = new BN(1e7); +let fee: BN = baseFee.div(new BN(1e9)); +fee = fee.add(new BN(1e6)); +``` + +Run the export script: + +```zsh +avalanchejs $ ts-node examples/evm/buildExportTx-xchain-avax.ts +Success! TXID: UAez3DTv26qmhKKFDvmQTayaXTPAVahHenDKe6xnUMhJbKuxc +``` + +#### Import the Avax Token From C-Chain to X-Chain + +Before we run the [example import script](https://github.com/ava-labs/avalanchejs/blob/master/examples/avm/buildImportTx-cchain.ts), we need to make some changes to the code: + +1. Change the [Network Setting](#network-setting) to meet Fuji network requirements. +2. Import your Private Key by following the steps listed [here](#private-key). +3. Run the Script! + +```zsh +avalanchejs $ ts-node examples/avm/buildImportTx-cchain.ts +Success! TXID: Sm6Ec2GyguWyG3Li1pARmTpaZ6qLEPuVAHV8QBGL9JWwWAEgM +``` + +## Mainnet Workflow + +The Fuji workflow above can be adapted to Mainnet with the following modifications: + +- The correct private key. +- Network setting should be to a Mainnet node, either [a local node on Mainnet](../nodes/maintain/avalanchego-config-flags.md#network-id) or [Avalanche Mainnet API server](../apis/avalanchego/public-api-server.md#using-the-public-api-nodes) where `api.avax.network` should be used for the `ip`. +- `const networkID: number = 1;` based on [this](../apis/avalanchejs/manage-x-chain-keys.md#encode-bech32-addresses). +- Set the correct amount to send. +- The correct receiving address. + +## Local Workflow + +### Start the Local Network + +Follow [Create a Local Test Network](../quickstart/create-a-local-test-network.md#avalanche-network-runner) to start a 5-node local network. Make sure that you get one of the port number by following [this](../quickstart/create-a-local-test-network.md#retrieve-all-nodes). In this tutorial, we will assume one of the ports is 30301. + +### Locate the Example Code and Make Necessary Changes + +Most of the code are already set to run it on a local network. Do check the following values to make sure they are correct. + +```js +const ip: string = "localhost"; +const port: number = 30301; // Change this to the correct value +const protocol: string = "http"; +const networkID: number = 1337; +``` + +Then run the export and import scripts to transfer tokens across chains. diff --git a/docs/quickstart/transfer-avax-between-p-chain-and-c-chain.md b/docs/quickstart/transfer-avax-between-p-chain-and-c-chain.md deleted file mode 100644 index 54b09fc592f..00000000000 --- a/docs/quickstart/transfer-avax-between-p-chain-and-c-chain.md +++ /dev/null @@ -1,260 +0,0 @@ -# Transfer AVAX Between the P-Chain and C-Chain - -## Introduction - -AVAX tokens exist on the X-Chain, where they can be traded, on the P-Chain, where they can be provided as a stake when validating the Primary Network, and on the C-Chain, where they can be used in smart contracts or to pay for gas. Avalanche supports movement of AVAX between these chains. In this tutorial, we’ll send AVAX tokens between the C-Chain and P-Chain. - -## Requirements - -You've completed [Getting Started](../nodes/build/run-avalanche-node-manually.md) and are familiar with [Avalanche's architecture](../overview/getting-started/avalanche-platform.md). - -In order to send AVAX, you need to have some AVAX! You can get real AVAX by buying it on an exchange, or you can get testnet AVAX from the [AVAX Test Faucet](https://faucet.avax.network), which is a free and easy way to get to play around with Avalanche. - -## Transferring AVAX Using the Web Wallet - -The easiest way to transfer AVAX between chains is to use [the Avalanche Wallet](https://wallet.avax.network/), which is a non-custodial and secure way to access and move AVAX. - -The Avalanche Wallet source code can be found [here](https://github.com/ava-labs/avalanche-wallet). - -### Step 1 - Open the Avalanche Wallet - -![Image for post](/img/wallet-x2p-01-login.png) - -Select **Access Wallet** to enter your wallet. To connect the wallet to a network other than the main Avalanche network, select **Mainnet** and choose the network to connect to. - -### Step 2 - Log In to Your Wallet - -You can access your wallet using the private key, mnemonic key phrase, keystore file or Ledger Nano S. - -![Image for post](/img/wallet-x2p-02-access.png) - -After a successful login you will see your balance, assets portfolio and various other information. - -### Step 3 - Go to the Cross Chain Tab - -![Image for post](/img/wallet-x2p-03-earn.png) - -Functionality for transferring tokens between chains is on the **Cross Chain** tab. - -### Step 4 - Enter Amount to Transfer - -You will be presented with a choice for **Source Chain** and **Destination Chain**. Select P-Chain and C-Chain, respectively. You will see your source chain's balance, and an input field for entering the amount to transfer from source to destination chain. If you do not have any balance on your P-Chain but on X-Chain, then you can follow this [tutorial](./transfer-avax-between-x-chain-and-p-chain.md) to transfer it to P-Chain. - -![Image for post](/img/wallet-p2c-04-p-c.png) - -Enter the amount you wish to transfer from the P-Chain to the C-Chain. - -### Step 5 - Confirm the Transaction - -![Image for post](/img/wallet-p2c-05-transfer.png) - -Press **Confirm**, and then **Transfer** to initiate the transfer. - -### Step 6 - Done! - -A cross-chain transfer is a two step process: first a transaction to export the funds from the P-Chain (source chain), and another to import it to the P-Chain (destination chain). The wallet will do both and show its the progress while doing so. - -![Image for post](/img/wallet-p2c-06-successful.png) - -That's it! You've transferred AVAX from the P-Chain to C-Chain! Now you can use them to deploy smart contracts on C-Chain or pay for transaction fees while interacting with smart contracts. - -### Transfer from C-Chain to P-Chain - -To return the AVAX back to the P-Chain, you need to do the transfer in the opposite direction. - -Swap the source and destination chains by selecting them from the **Source** and **Destination** drop-down menu. The rest of the process is the same: enter the amount, confirm and transfer. - -## Transferring from the P-Chain to C-Chain with API Calls - -If you're building an application on the Avalanche network, you may want to do the transfer programmatically as part of some broader functionality. You can do that by calling the appropriate APIs on an AvalancheGo node. The rest of the tutorial assumes you have access to an AvalancheGo node, AVAX tokens on the P-Chain, and user credentials [created](../apis/avalanchego/apis/keystore.md#keystorecreateuser) and stored in the node's keystore. - -All the example API calls below assume the node is running locally (that is, listening on `127.0.0.1`). The node can be connected to the main network, a test network or a local network. In each case, the API calls and responses should be the same, except for the address formats. The node need not be local; you can make calls to a node hosted elsewhere. - -As you may have noticed while transferring AVAX using the Avalanche Wallet, a cross-chain transfer is a two transaction operation: - -* Export AVAX from the P-Chain (source) -* Import AVAX to the C-chain (destination) - -Before we can do the transfer, we need to set up the address on the C-Chain, along with the controlling key. - -### Set Up Address and Key on the C-Chain - -The P-Chain and X-Chain uses [Bech32](http://support.avalabs.org/en/articles/4587392-what-is-bech32) addresses and the C-Chain uses hex Ethereum Virtual Machine (EVM) addresses. There is no way to convert the address from one format to the other since they are both derived from a private key using a one-way cryptographic function. - -In order to get around this, you can export a private key from the X-Chain and then import it to the C-Chain. This way, you can use the X-Chain address and change the X- prefix to a C- prefix in order to get the correct Bech32 address to use for the C-Chain. - -First, export a private key from the X-Chain: - -```sh -curl -X POST --data '{ - "jsonrpc":"2.0", - "id" :1, - "method" :"avm.exportKey", - "params" :{ - "username" :"myUsername", - "password":"myPassword", - "address": "X-avax1fw57u4tp7xzx0k6ufn7tj9caua59mt9gqcvy7m" - } -}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X -``` - -Response: - -```json -{ - "jsonrpc":"2.0", - "id" :1, - "result" :{ - "privateKey":"PrivateKey-2w4XiXxPfQK4TypYqnohRL8DRNTz9cGiGmwQ1zmgEqD9c9KWLq" - } -} -``` - -Now, import the same private key to the C-Chain: - -```sh -curl -X POST --data '{ - "jsonrpc":"2.0", - "id" :1, - "method" :"avax.importKey", - "params" :{ - "username" :"myUsername", - "password":"myPassword", - "privateKey":"PrivateKey-2w4XiXxPfQK4TypYqnohRL8DRNTz9cGiGmwQ1zmgEqD9c9KWLq" - } -}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax -``` - -The response contains a hex-encoded EVM address: - -```json -{ - "jsonrpc": "2.0", - "result": { - "address": "0x5Bf544EF123FE41B262295dBA41c5a9CFA8efDB4" - }, - "id": 1 -} -``` - -Now we have everything we need to transfer the tokens. - -### Transfer from the P-Chain to C-Chain - -Use the address corresponding to the private key you exported and switch to using the C- prefix in the [`platform.exportAVAX`](../apis/avalanchego/apis/p-chain.md#platformexportavax) call: - -```sh -curl -X POST --data '{ - "jsonrpc":"2.0", - "id" :1, - "method" :"platform.exportAVAX", - "params" :{ - "assetID": "AVAX", - "to": "C-avax1fw57u4tp7xzx0k6ufn7tj9caua59mt9gqcvy7m" - "amount": 5000000, - "username":"myUsername", - "password":"myPassword" - } -}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/P -``` - -Since your keystore user owns the corresponding private key on the C-Chain, you can now import the AVAX to the address of your choice. It’s not necessary to import it to the same address that it was exported to; you can import the AVAX to an address that you own in MetaMask or another third-party service. - -```sh -curl -X POST --data '{ - "jsonrpc":"2.0", - "id" :1, - "method" :"avax.import", - "params" :{ - "to":"0x4b879aff6b3d24352Ac1985c1F45BA4c3493A398", - "sourceChain":"P", - "username":"myUsername", - "password":"myPassword" - } -}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax -``` - -where `to` is a hex-encoded EVM address of your choice. - -The response looks like this: - -```json -{ - "jsonrpc": "2.0", - "result": { - "txID": "LWTRsiKnEUJC58y8ezAk6hhzmSMUCtemLvm3LZFw8fxDQpns3" - }, - "id": 1 -} -``` - -Note: there is no transaction fee for import transactions to the C Chain. - -Once your AVAX has been transferred to the C-Chain, you can use it to deploy and interact with smart contracts. - -## Transfer from the C-Chain to P-Chain - -Now, you can move AVAX back from the C-Chain to the P-Chain. First we need to export: - -```sh -curl -X POST --data '{ - "jsonrpc":"2.0", - "id" :1, - "method" :"avax.exportAVAX", - "params" :{ - "to":"P-avax1fw57u4tp7xzx0k6ufn7tj9caua59mt9gqcvy7m", - "assetID": "AVAX", - "amount": 5000000, - "username":"myUsername", - "password":"myPassword" - } -}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax -``` - -where `to` is the bech32 encoded address of an P-Chain address you hold. Make sure that the amount you export exceeds the transaction fee because both the export and import transactions will charge a transaction fee. - -The response should look like this: - -```json -{ - "jsonrpc": "2.0", - "result": { - "txID": "2ZDt3BNwzA8vm4CMP42pWD242VZy7TSWYUXEuBifkDh4BxbCvj" - }, - "id": 1 -} -``` - -To finish the transfer, call P-Chain’s [`platform.importAVAX`](../apis/avalanchego/apis/p-chain.md#platformimportavax) - -```sh -curl -X POST --data '{ - "jsonrpc":"2.0", - "id" :1, - "method": "platform.importAVAX", - "params": { - "username":"myUsername", - "password":"myPassword", - "sourceChain": "C", - "to":"P-avax1fw57u4tp7xzx0k6ufn7tj9caua59mt9gqcvy7m" - } -}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/P -``` - -where `to` is the bech32 encoded address the P-Chain address which you sent the funds to in the previous step. - -The response should look like this: - -```json -{ - "jsonrpc": "2.0", - "result": { - "txID": "2kxwWpHvZPhMsJcSTmM7a3Da7sExB8pPyF7t4cr2NSwnYqNHni" - }, - "id": 1 -} -``` - -## Wrapping Up - -That’s it! Now, you can swap AVAX back and forth between the P-Chain and C-Chain, both by using the Avalanche Wallet, and by calling the appropriate API calls on an Avalanche node. diff --git a/docs/subnets/create-a-fuji-subnet.md b/docs/subnets/create-a-fuji-subnet.md index 089d189e18e..2684d424746 100644 --- a/docs/subnets/create-a-fuji-subnet.md +++ b/docs/subnets/create-a-fuji-subnet.md @@ -83,7 +83,7 @@ To get fund on this key on Fuji TestNet, follow these steps: 1. User your private key in the `.subnet-cli.pk` file on the [web wallet](https://wallet.avax.network) to access this wallet. (Private Key is the first option on the [web wallet](https://wallet.avax.network)). And pick **Fuji** on the top right corner as the network and locate your C-Chain address which starts with `0x`. 2. Request funds from the [faucet](https://faucet.avax.network) using your C-Chain address. -3. Move the test funds from the C-Chain to the P-Chain by clicking on the `Cross Chain` on the left side of the web wallet (more details can be found on the [tutorial between C/P chains](../quickstart/transfer-avax-between-p-chain-and-c-chain.md)). +3. Move the test funds from the C-Chain to the P-Chain by clicking on the `Cross Chain` on the left side of the web wallet (more details can be found on the [tutorial between C/P chains](../quickstart/cross-chain-transfers.md)). After following these 3 steps, your test key should now have a balance on the P-Chain on Fuji Testnet. diff --git a/docs/subnets/subnet-cli.md b/docs/subnets/subnet-cli.md index 44799cb1c76..cb6caa35793 100644 --- a/docs/subnets/subnet-cli.md +++ b/docs/subnets/subnet-cli.md @@ -113,7 +113,7 @@ To get fund on this key on Fuji TestNet, follow these steps: 1. User your private key in the `.subnet-cli.pk` file on the [web wallet](https://wallet.avax.network) to access this wallet. (Private Key is the first option on the [web wallet](https://wallet.avax.network)). And pick **Fuji** on the top right corner as the network and locate your C-Chain address which starts with `0x`. 2. Request funds from the [faucet](https://faucet.avax.network) using your C-Chain address. -3. Move the test funds from the C-Chain to the P-Chain by clicking on the `Cross Chain` on the left side of the web wallet (more details can be found on the [tutorial between C/P chains](../quickstart/transfer-avax-between-p-chain-and-c-chain.md)). +3. Move the test funds from the C-Chain to the P-Chain by clicking on the `Cross Chain` on the left side of the web wallet (more details can be found on the [tutorial between C/P chains](../quickstart/cross-chain-transfers.md)). After following these 3 steps, your test key should now have a balance on the P-Chain on Fuji Testnet. @@ -527,4 +527,4 @@ Checking blockchain... 2022-05-20T16:20:57.367-0600 info platformvm/checker.go:148 waiting for blockchain status {"current": "Created"} 2022-05-20T16:20:58.368-0600 info platformvm/checker.go:148 waiting for blockchain status {"current": "Created"} ...... -``` +``` \ No newline at end of file diff --git a/sidebars.js b/sidebars.js index c99663b1dd4..101a60a7835 100644 --- a/sidebars.js +++ b/sidebars.js @@ -48,9 +48,7 @@ const sidebars = { 'quickstart/create-a-local-test-network', 'quickstart/fund-a-local-test-network', 'quickstart/fuji-workflow', - 'quickstart/transfer-avax-between-x-chain-and-c-chain', - 'quickstart/transfer-avax-between-x-chain-and-p-chain', - 'quickstart/transfer-avax-between-p-chain-and-c-chain', + 'quickstart/cross-chain-transfers', 'quickstart/multisig-utxos-with-avalanchejs', 'quickstart/transaction-fees', 'quickstart/adjusting-gas-price-during-high-network-activity', diff --git a/static/_redirects b/static/_redirects index fb852b6e81d..4cc36bc13c7 100644 --- a/static/_redirects +++ b/static/_redirects @@ -1,3 +1,11 @@ +#06/01/2022 transfer-avax-between-x-ch +/quickstart/transfer-avax-between-x-chain-and-c-chain/ /quickstart/cross-chain-transfers 301 +/quickstart/transfer-avax-between-x-chain-and-c-chain /quickstart/cross-chain-transfers 301 +/quickstart/transfer-avax-between-x-chain-and-p-chain/ /quickstart/cross-chain-transfers 301 +/quickstart/transfer-avax-between-x-chain-and-p-chain /quickstart/cross-chain-transfers 301 +/quickstart/transfer-avax-between-p-chain-and-c-chain/ /quickstart/cross-chain-transfers 301 +/quickstart/transfer-avax-between-p-chain-and-c-chain /quickstart/cross-chain-transfers 301 + #05/30/2022 /subnets/create-custom-blockchain/ /subnets/create-a-fuji-subnet 301 /subnets/create-custom-blockchain /subnets/create-a-fuji-subnet 301 @@ -233,12 +241,12 @@ /build/tutorials/platform/fund-a-local-test-network /quickstart/fund-a-local-test-network 301 /build/tutorials/platform/integrate-exchange-with-avalanche/ /quickstart/exchanges/integrate-exchange-with-avalanche 301 /build/tutorials/platform/integrate-exchange-with-avalanche /quickstart/exchanges/integrate-exchange-with-avalanche 301 -/build/tutorials/platform/transfer-avax-between-x-chain-and-c-chain/ /quickstart/transfer-avax-between-x-chain-and-c-chain 301 -/build/tutorials/platform/transfer-avax-between-x-chain-and-c-chain /quickstart/transfer-avax-between-x-chain-and-c-chain 301 -/build/tutorials/platform/transfer-avax-between-x-chain-and-p-chain/ /quickstart/transfer-avax-between-x-chain-and-p-chain 301 -/build/tutorials/platform/transfer-avax-between-x-chain-and-p-chain /quickstart/transfer-avax-between-x-chain-and-p-chain 301 -/build/tutorials/platform/transfer-avax-between-p-chain-and-c-chain/ /quickstart/transfer-avax-between-p-chain-and-c-chain 301 -/build/tutorials/platform/transfer-avax-between-p-chain-and-c-chain /quickstart/transfer-avax-between-p-chain-and-c-chain 301 +/build/tutorials/platform/transfer-avax-between-x-chain-and-c-chain/ /quickstart/cross-chain-transfers 301 +/build/tutorials/platform/transfer-avax-between-x-chain-and-c-chain /quickstart/cross-chain-transfers 301 +/build/tutorials/platform/transfer-avax-between-x-chain-and-p-chain/ /quickstart/cross-chain-transfers 301 +/build/tutorials/platform/transfer-avax-between-x-chain-and-p-chain /quickstart/cross-chain-transfers 301 +/build/tutorials/platform/transfer-avax-between-p-chain-and-c-chain/ /quickstart/cross-chain-transfers 301 +/build/tutorials/platform/transfer-avax-between-p-chain-and-c-chain /quickstart/cross-chain-transfers 301 /build/tutorials/platform/adjusting-gas-price-during-high-network-activity/ /quickstart/adjusting-gas-price-during-high-network-activity 301 /build/tutorials/platform/adjusting-gas-price-during-high-network-activity /quickstart/adjusting-gas-price-during-high-network-activity 301 /build/tutorials/platform/sending-transactions-with-dynamic-fees-using-javascript/ /quickstart/sending-transactions-with-dynamic-fees-using-javascript 301