Implementation Steps

1

Setup Prerequisites

Ensure you have the following installed:

  • Node.js (v16 or higher)
  • TypeScript and ts-node
  • Environment variables configured
2

Initialize Project

Create and set up a new Node.js project:

mkdir contract-call-example
cd contract-call-example
npm init -y
3

Install Dependencies

Install the required packages:

npm install ethers dotenv @aarc-xyz/core-viem
npm install --save-dev typescript ts-node
4

Configure TypeScript

Create a tsconfig.json file:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "strict": true,
    "esModuleInterop": true
  }
}
5

Setup Environment Variables

Create a .env file in the root directory:

API_KEY=your_aarc_api_key
PRIVATE_KEY=your_private_key
RPC_URL=your_rpc_url

Ensure dotenv is loaded in your script to access these variables.

6

Create Implementation File

Create a new file contract-call-example.ts with the following components:

import { config } from 'dotenv';
import { ethers } from 'ethers';
import { AarcCore } from '@aarc-xyz/core-viem';

config();
const API_KEY = process.env.API_KEY!;
const PRIVATE_KEY = process.env.PRIVATE_KEY!;
const RPC_URL = process.env.RPC_URL!;
7

Run Implementation

Execute the script:

npx ts-node contract-call-example.ts
8

Handle Output

Monitor the following outputs:

  • Wallet balances
  • Generated call data
  • Deposit address
  • Transaction hash
  • Polling status updates until completion
9

Error Handling

Implement proper error handling:

  • Use try...catch blocks for API errors
  • Validate input parameters
  • Check for insufficient balances
  • Handle unavailable routes
  • Log descriptive error messages

For a more comprehensive implementation of polling, refer to our polling example.

Now you can checkout to a cross-chain contract call with different payment methods. :tada: