Prerequisites
Before you begin, ensure that you’ve:- Installed Node.js v18+ and npm.
- Created an Ethereum Sepolia wallet and funded it with testnet USDC and native
tokens:
- Use a wallet provider such as MetaMask to create a wallet on Ethereum Sepolia.
- Get testnet USDC from the Circle Faucet.
- Get testnet ETH from a public Ethereum Sepolia faucet.
Step 1. Set up your project
This step shows you how to step up a fresh Node.js workspace, install dependencies, configure your environment variables, and prepare your Ethereum Sepolia wallet.1.1. Set up your development environment
Create a new directory and install dependencies:Shell
1.2 Configure environment variables
Create a.env file in the project directory and add your wallet private key,
replacing {YOUR_PRIVATE_KEY} with the private key for your Ethereum Sepolia
Wallet.
Shell
Step 2. Set up your script
This step shows you how to build the script by importing its dependencies and defining the configuration constants and ABI fragments that the script uses.2.1. Import dependencies
Create a file calledindex.mjs and add the following code to it. This code
imports the dependencies that the script uses.
index.mjs
2.2. Define configuration constants
Add the highlighted code snippet toindex.mjs. It specifies the RPC and wallet
private key, contract addresses, and Canton-specific parameters that the rest of
the script relies on. Replace your_canton_wallet_address with the wallet that
should receive minted USDCx on Canton TestNet.
index.mjs
2.3. Set up contract ABIs
Add the highlighted code snippet toindex.mjs. It adds xReserve and ERC-20 ABI
fragments which tell Viem how to format and send the contract calls when the
script runs.
index.mjs
Step 3. Execute the xReserve deposit
This step shows you how to implement the main logic that checks balances, approves USDC, and calls xReserve on Ethereum Sepolia so Canton can mint the corresponding USDCx.3.1. Add the main function
Add the highlighted code snippet toindex.mjs. This code flows through the
following actions:
- Verifies that
PRIVATE_KEYis present before continuing. - Creates an Ethereum Sepolia wallet client and logs the originating address.
- Checks native ETH balance to ensure there is enough gas for transactions.
- Computes the deposit value, maximum fee, and Canton recipient payload (USDC uses 6 decimals).
- Confirms that the wallet’s USDC balance covers the configured deposit amount.
- Approves the xReserve smart contract to spend USDC on the wallet’s behalf.
- Calls
depositToRemoteto submit the deposit and tell Canton to mint USDCx for the wallet specified as theCANTON_RECIPIENT.
index.mjs
3.2. Run the script
Save theindex.mjs file and execute the script in your terminal:
Shell
3.3. Verify the deposit
After the script finishes, find theDeposit tx hash in the terminal output and
paste it into Sepolia Etherscan to confirm your
deposit transaction was successful. On Canton TestNet, the recipient wallet will
receive the minted testnet USDCx.