Sometimes you just need to create hundreds of links. Here is how you can!
Batch Create Links using EthersV5
If you are using EthersV5 as your signer, you can call the createLinks function to produce multiple Peanut Links at once.
import peanut, { getDefaultProvider } from'@squirrel-labs/peanut-sdk'import { Wallet } from'ethersv5'constchainId='11155111'// Sepoliaconstmnemonic='announce room limb pattern dry unit scale effort smooth jazz weasel alcohol'asyncfunctioncreateLinks():Promise<string[]> {let wallet =Wallet.fromMnemonic(mnemonic)constprovider=awaitgetDefaultProvider(chainId) wallet =wallet.connect(provider)constlinkDetails= { chainId: chainId, tokenAmount:0.001, tokenType:0,// 0 for ether, 1 for erc20, 2 for erc721, 3 for erc1155 tokenDecimals:18, }constcreatedLinks=awaitpeanut.createLinks({ structSigner: { signer: wallet, }, linkDetails, numberOfLinks:5, })returncreatedLinks.map((link) =>link.link)}createLinks().then(() =>console.log('Congrats!!'))
Batch Create Links using Signer Agnostic Functions:
You're not using Ethersv5, but some other signing library (viem, web3js, wagmi, inhouse etc)? No problem! You will have to prepare the transactions(s), submit the transaction with your wallet, and use the resulting transaction hash to generate the links. The following code is an example that does not use a particular signer.