Buy Tokens

The getDepositAddress function generates a smart account address that facilitates user operations. In this section, we’ll explore how to use this function to seamlessly bridge funds across chains.

Expected parameters

getDepositAddress accepts the following parameters:

Parameter
Type
Description

destinationChainId

string

Destination chain id

destinationTokenAddress

string

Address of the final token on the destination chain

toAmount

BigInt

Desired amount on destination chain

destinationRecipient

string

Target contract address on destination chain

transferType

"onramp" | "cex" | "wallet"

Specifies the type of the transfer

routeType

string

Default route is Value. The type of route to be preferred. It can be Value,Fee and Time

provider (optional)

"moonpay" | "mesh-connect" | "kado"

Specifies the provider used for execution

fromChainId (optional)

number

Source chain id

fromTokenAddress (optional)

string

Address of initial token on source chain

fromAddress (optional)

string

Address of the sender on the source chain

fromAmount (optional)

BigInt

Amount of the initial token on the source chain

slippage (optional)

string

transferOut (optional)

any[]

targetCalldata(optional)

string

Encoded calldata for execution on the destination chain

gasLimit (optional)

string

Custom gas limit

userOpHash (optional)

string

userOperations (optional)

string

Function call

The getDepositAddress function generates an address based on the provided payload, which must then be funded and submitted on-chain.

const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

const payload: any = {
        userOpHash: "",
        transferType: TransferType.WALLET,
        destinationChainId: "8453",
        destinationTokenAddress: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
        toAmount: BigInt(Math.floor(0.01 * 10 ** 8),
        destinationRecipient: "0x45c0470ef627a30efe30c06b13d883669b8fd3a8",
        fromTokenAddess: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
        fromChainId: "42161",
        fromAddress: "0xeDa8Dec60B6C2055B61939dDA41E9173Bab372b2",
};

const depositData = await aarcCoreSDK.getDepositAddress(payload); 

// make client sign the generated tx
const { to, value, data, gasLimit, chainId, from } = depositData.txData;
const { hash } = await signer.sendTransaction({ to, value, data, gasLimit, chainId, from });
//OPTIONAL: postExecuteToAddress will update the aarc about the tx instanstly
await aarcCoreSDK.postExecuteToAddress({
          depositData,
          hash,
}); 

Using onramp

// Using moonpay for onramp (you can also use kado)
const payload = {
    // rest of the payload,
    transferType: "onramp"  
}

const provider = "moonpay";

const depositData = await aarcCoreSDK.getDepositAddress(payload);

 const fromToken = {
        chainId: 8453,
        token_address: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
        amount_required: "35",
        decimals: 6,
      };

const url = await aarcCoreSDK.generateMoonpayOnrampUrl({
        walletAddress: depositData.depositAddress,
        defaultCryptoCurrencyCode: depositData.depositTokenSymbol,
        fiatAmount: fromToken.amount_required,
        fiatCurrencyCode: "USD",
        network: "BASE",
        cryptoTokenData: {
          tokenAmount: fromToken.amount_required,
          tokenCode: depositData.depositTokenSymbol ?? "ETH",
        },
      });

const windowRef = window.open(url, "_blank");

Response

The response from the getDepositAddress is:

{
    requestId: string; // helps tracking the order status
    status: string;
    executionTime: string;
    gasFee: string;
    depositAddress: string;
    onChainID: string;
    depositTokenAddress: string;
    amount: string;
    usdFee?: string;
    depositTokenDecimals?: string;
    depositTokenName?: string;
    depositTokenSymbol?: string;
    depositTokenUsdPrice?: number;
    data?: {
        error?: string;
        message?: string;
    };
    txData: {
        chainId: string;
        from: string;
        to: string;
        data: string;
        value: string;
        gasLimit: string;
    };
}

For more comprehensive implementation, refer cookbook example.

Support

If you face any trouble, feel free to reach out to our engineers in the Telegram support group.

Last updated