Create Request Link

Request Links make it easy to ask for tokens or payments.

Creating both Crosschain Request Links and Normal Links follows the same process as shown in the example.

import peanut from '@squirrel-labs/peanut-sdk';

const recipientAddress = '0x42A5DC31169Da17639468e7Ffa271e90Fdb5e85A';
const tokenAddress = '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85'; // USDC on Optimism
const chainId = '10';  // Optimism
const tokenAmount = '10';
const tokenDecimals = '6';
const APIKey = 'api-key';
const apiUrl = 'api-url';

async function createRequestLink(): Promise<string | null> {
  try {
    const { link } = await peanut.createRequestLink({
      chainId,
      tokenAddress,
      tokenAmount,
      tokenType: EPeanutLinkType.erc20, // or EPeanutLinkType.native
      tokenDecimals,
      recipientAddress,
      APIKey,
      apiUrl,
    });
    return link;
  } catch (error) {
    console.error('Error creating request link:', error);
    return null;
  }
}

// Call the function and log the link
createRequestLink().then((link) => console.log(link));

Last updated