If you want a Link to hold multiple tokens (e.g. an NFT, some USDC and some Ether for gas), then you can create a Multi-Token Link. To do this, you'll have to first create n
links with the same password p
. Then, you can invoke peanut.createMultiLinkFromLinks(links)
to get the Multi-Token Link. Easy!
Note: you can also create Links using the signer agnostic functions (check Create Link) and pass these Links into the createMultiLinkFromLinks()
function.
import peanut, { getDefaultProvider } from '@squirrel-labs/peanut-sdk'
import { Wallet } from 'ethersv5'
const chainId = '137' // polygon
const mnemonic = 'announce room limb pattern dry unit scale effort smooth jazz weasel alcohol'
async function createLinks(): Promise<string> {
let wallet = Wallet.fromMnemonic(mnemonic)
const provider = await getDefaultProvider(chainId)
wallet = wallet.connect(provider)
const { link, txHash } = await peanut.createLink({
structSigner: {
signer: wallet,
},
linkDetails: {
chainId: chainId,
tokenAmount: 0.01,
tokenType: 0, // 0 for ether, 1 for erc20, 2 for erc721, 3 for erc1155
tokenDecimals: 18,
},
})
const { link: link2, txHash: txHash2 } = await peanut.createLink({
structSigner: {
signer: wallet,
},
linkDetails: {
chainId: chainId,
tokenAmount: 0.01,
tokenType: 1, // 0 for ether, 1 for erc20, 2 for erc721, 3 for erc1155
tokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC
tokenDecimals: 6,
},
})
const multiLink = peanut.createMultiLinkFromLinks([link, link2])
return multiLink
}
createLinks().then((link) => console.log(link))