Prerequisites

  • Node.js and npm installed
  • An Ethereum wallet with private key
  • API key from Aarc
  • Basic understanding of TypeScript and Ethereum

Setup

1

Environment Setup

Create a .env file with your credentials:

PRIVATE_KEY=your_private_key
RPC_URL=your_arbitrum_rpc_url
API_KEY=your_aarc_api_key
2

Install Dependencies

Install the required packages:

npm install ethers axios dotenv

Implementation

1

Configure Constants

Define the necessary constants for the USDT contract and destination details:

const USDT_ADDRESS = "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9";
const DESTINATION_TOKEN = {
    decimals: 6, // USDT decimals
    chainId: 42161, // Arbitrum chain ID
    address: USDT_ADDRESS,
};
2

Generate Mint Call Data

Create a function to generate the calldata for minting USDT:

function generateStablecoinCallData(
    toAddress: string,
    amount: string
): string {
    const usdtInterface = new ethers.Interface([
        "function mint(address _destination, uint256 _amount) external"
    ]);

    return usdtInterface.encodeFunctionData("mint", [
        toAddress,
        amount
    ]);
}
3

Implement Minting Function

Create the main function that handles the minting process:

async function mintStablecoin(amount: string) {
    try {
        // Generate mint calldata
        const callData = generateStablecoinCallData(
            DESTINATION_WALLET,
            amount
        );

        // Get deposit address from Aarc
        const depositData = await getDepositAddress({
            destinationChainId: DESTINATION_TOKEN.chainId.toString(),
            destinationTokenAddress: DESTINATION_TOKEN.address,
            toAmount: amount,
            destinationRecipient: USDT_ADDRESS,
            transferType: 'wallet',
            targetCalldata: callData,
        });

        // Schedule the transaction
        const scheduledTx = await scheduleTransaction({
            requestId: depositData.requestId,
            fromAddress: DESTINATION_WALLET,
            toAddress: depositData.depositAddress,
            token: DESTINATION_TOKEN.address,
            amount: amount,
        });

        // Execute the transaction
        const txHash = await executeTransaction(depositData.txData);
        return txHash;
    } catch (error) {
        console.error("Error in stablecoin minting process:", error);
        throw error;
    }
}
4

Execute the Minting

Call the function with the desired amount:

// Mint 1 USDT (1000000 = 1 USDT with 6 decimals)
mintStablecoin("1000000");

Understanding the Flow

  1. Generate Calldata: Creates the encoded function call for minting USDT.
  2. Get Deposit Address: Obtains a unique deposit address from Aarc for the transaction.
  3. Schedule Transaction: Notifies Aarc about the upcoming transaction for faster processing.
  4. Execute Transaction: Sends the transaction to the blockchain.

Complete Example

For the complete implementation, including utility functions and more detailed error handling, check out our [example repository]https://github.com/aarc-xyz/execution-api-examples/blob/main/src/examples/mint-stablecoin.ts).