This quickstart provides all the code you need to create a unified crosschain
balance and transfer it to Solana. You can find the full code for this
quickstart on
GitHub.
Prerequisites
Before you begin, ensure you have:- Node.js and npm installed on your development machine.
- Two wallets on Solana Devnet, with addresses and private key pairs available.
- You need two Solana accounts to act as sender and recipient in the Solana same-chain transfer example. If you don’t plan to run the example, you can have only one Solana account.
- One Solana wallet funded with USDC and native tokens.
- The funded wallet acts as the sender and fee payer.
- Use the Circle Faucet to get 1 USDC on Solana Devnet.
- Use the Solana Devnet faucet to get testnet native tokens (SOL).
Shell
.env file.
Step 1: Set up your project
The following sections demonstrate how to initialize your project and set up the required clients and smart contracts to interact with Circle Gateway.1.1. Set up your development environment
Create a new directory for your project and initialize it with npm. Set the package type tomodule and install the necessary dependencies:
Shell
.env file.
Shell
.env file and add the following variables. Replace
{YOUR_SOLANA_PRIVATE_KEYPAIR_1} and {YOUR_SOLANA_PRIVATE_KEYPAIR_2} with
your Solana key pairs in JSON array format. Note that SOLANA_PRIVATE_KEYPAIR_1
should be the wallet with fund:
1.2. Define contract IDLs
Create asolana directory for Solana-specific code:
Shell
idls.js in the solana directory and add the following
code to it. This helper code defines the contract functions that you use to
establish a unified USDC balance and mint it on a new blockchain.
For brevity, the IDLs in this code are not complete IDLs for the wallet and
minter contracts. They only define the functions necessary for this
quickstart. See Contract Interfaces and
Events for a full
description of each contract’s methods.
JavaScript
1.3. Define the Gateway API client
Create a file calledgateway-client.js in the project root directory and add
the following code to it. This helper code provides data and methods for
interacting with the Gateway API.
JavaScript
1.4. Prepare ready-to-sign burn intent
This step shows you how to transform a raw burn intent into one that is ready to sign.1.4.1 Transform format of burn intent fields based on the chain
Create a file calledburnIntentTransformers.js in the project root directory
that can be shared by EVM and Solana, and add the following code to it:
JavaScript
1.4.2 Encode burn intent(set)
This section corresponds to Step 1.4 in the EVM
quickstart.
burnIntent.js in the solana directory
and add the following code to it:
JavaScript
1.5. Decode attestation
Create a file calledattestation.js in the solana directory and add the
following code to it:
JavaScript
1.6. Initialize clients and contracts
1.6.1 Define wallet and minter clients
You only need to define clients for Solana. For EVM, thegetContract function
provided by the viem library handles client setup.
[1] Solana wallet client
Create a file called solanaWalletClient.js in the solana directory and add
the following code to it.
JavaScript
solanaMinterClient.js in the solana directory and add
the following code to it.
JavaScript
1.6.2 Account setup
Create a file calledsetup.js in the solana directory and add the following
code to it. This setup code initializes Solana wallet and minter clients that
you’ll use to interact with the Gateway program on Solana.
Remember to add Solana key pairs to your
.env file as shown in the preceding
environment setup step.JavaScript
Step 2: Create a unified crosschain balance
In this step, you deposit USDC into the Gateway Wallet contract on the source chain, creating a unified crosschain balance for your address in Gateway.2.1. Deposit USDC into the Gateway Wallet contracts
Create a file calleddeposit.js in the solana directory and add the
following code to it. This script deposits USDC into the Gateway Wallet
contracts on Solana.
Note that for the transfer, the code is not calling the ERC-20 transfer
function, as doing so would result in a loss of funds. Instead, the code calls
gateway_deposit instruction provided by the Gateway Wallet contract to
transfer USDC on behalf of your account.
JavaScript
2.2. Run the script to create a crosschain balance
Run thedeposit.js script to make the deposit. If you don’t have enough USDC
for the deposit or enough testnet native tokens to pay for gas fees, the code
returns an error message.
Shell
You must wait for finality on the blockchain for the unified balance to be
updated. On Solana Devnet, finality is typically reached within a few seconds.
Step 3: Transfer USDC from the crosschain balance to Solana
In this step, you create a burn intent, submit it to the transfer API, and receive an attestation, which you can use to mint USDC on Solana. This quickstart demonstrates two transfer scenarios involving Solana:- EVM to Solana: Cross-ecosystem transfer from Avalanche Fuji to Solana Devnet
- Solana to Solana: Transfer USDC between Solana Devnet accounts
3.1. Sign burn intents
Create a folder calledtransfers in the project root directory and add the
following code to it. The code checks that the Gateway API supports the
blockchains you want to use and confirms that your balance on the source
blockchains is sufficient to complete the transfer.
This section provides two transfer scenarios for reference.
- EVM to Solana
- Solana to Solana
To run this example, you must first complete Steps 1-2 of the EVM
quickstart to set up your EVM
environment and deposit USDC on Avalanche Fuji.
transfers folder, create a file called avaxToSolana.js and add the
following code to it.JavaScript
3.2. Submit burn intents to the API
Add the following code toavaxToSolana.js to submit the burn intents to the
Gateway in exchange for an attestation:JavaScript
3.3. Mint USDC on Solana
Add the following code toavaxToSolana.js to mint USDC on Solana using the
attestation:JavaScript
3.4. Run the transfer script
Run theavaxToSolana.js script:Shell