Creating a request link is easy you will need to have your api key (get one here!) and the following data for the request:
Example code:
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 = 'YOUR-API-KEY-HERE';
async function createRequestLink(): Promise<string | undefined> {
try {
const { link } = await peanut.createRequestLink({
chainId,
tokenAddress,
tokenAmount,
tokenType: peanut.interfaces.EPeanutLinkType.erc20, // or EPeanutLinkType.native
tokenDecimals,
recipientAddress,
APIKey,
// apiUrl: '' // if using a different api endpoint
});
return link;
} catch (error) {
console.error('Error creating request link:', error);
return undefined
}
}
// Call the function and log the link
createRequestLink().then((link) => console.log(link));