SDK
The Connext SDK allows developers to interact with the Connext protocol in standard Node.js or web environments. See here for a reference of all SDK methods.
Cross-Chain Transfer
This example demonstrates how to execute an xcall to transfer funds from a wallet on the source domain to the same address on the destination domain.
1. Setup
Install Node.js and use Node.js v18. Follow the instructions to install nvm, a node version manager, which will make switching versions easier.
Create a project folder and initialize the package. Fill out the project information as you please.
mkdir connext-sdk-example && cd connext-sdk-example
npm initWe'll be using TypeScript so install the following and generate the tsconfig.json file.
npm install --save-dev @types/node @types/chai @types/mocha typescript
npx tsc --init # or `yarn tsc --init`We want to use top-level await so we'll set the compiler options accordingly in tsconfig.json:
{
"compilerOptions": {
"outDir": "./dist",
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"exclude": ["node_modules"]
}Add type and scripts as root-level entries to package.json - they may already exist, so just replace them with the following.
2. Install dependencies
Install the latest beta version of Connext SDK and ethers.
3. The code
First, we'll configure the SDK. Create a config.ts file with the following contents.
Replace <PRIVATE_KEY> with your own private key on line 5.
Notice that the config supports Goerli and Optimism-Goerli. We've also hard-coded the origin chain provider on line 10.
Now create a xtransfer.ts file with the following:
Most of the parameters are hardcoded in this example. For a detailed description of each parameter, see the SDK reference for xcall.
Information like asset addresses be found in the Deployments page.
4. Run it
Fire off the cross-chain transfer!
5. Track the xcall
xcallWe can now use the transaction hash from the logged transaction receipt to track the status of this xcall.
After the transfer is status: Executed on the destination side, the transferred tokens should show up in the recipient wallet.
Last updated