Want to send an NFT through a link? Have a look here how you can!
For ERC721
The following example shows how you can create an NFT Link that holds an ERC721 token type.
plain textimport peanut, { getDefaultProvider } from '@squirrel-labs/peanut-sdk' import { Wallet } from 'ethersv5' const chainId = '11155111' // Sepolia const mnemonic = 'announce room limb pattern dry unit scale effort smooth jazz weasel alcohol' async function createLink(): Promise<string | null> { let wallet = Wallet.fromMnemonic(mnemonic) const provider = await getDefaultProvider(chainId) wallet = wallet.connect(provider) const linkDetails:{ chainId: chainId, tokenAddress: [ERC721 token address], tokenAmount: 1, tokenType: 2, // 2 is for ERC721 tokens tokenId: [NFT tokenID] } const password = await peanut.getRandomString(16) const preparedTransactions = await peanut.prepareDepositTxs({ address: wallet.address, linkDetails, passwords: [password], }) const transactionHashes: string[] = [] for (const unsignedTx of preparedTransactions.unsignedTxs) { const convertedTx = peanut.peanutToEthersV5Tx(unsignedTx) const signedTx = await wallet.sendTransaction(convertedTx) transactionHashes.push(signedTx.hash) } const { links } = await peanut.getLinksFromTx({ linkDetails, passwords: [password], txHash: transactionHashes[transactionHashes.length - 1], }) return links[0] } createLink().then((link) => console.log(link))
For ERC1155:
The following example shows how you can create an NFT Link that holds an ERC1155 token type.
plain textimport peanut, { getDefaultProvider } from '@squirrel-labs/peanut-sdk' import { Wallet } from 'ethersv5' const chainId = '11155111' // Sepolia const mnemonic = 'announce room limb pattern dry unit scale effort smooth jazz weasel alcohol' async function createLink(): Promise<string | null> { let wallet = Wallet.fromMnemonic(mnemonic) const provider = await getDefaultProvider(chainId) wallet = wallet.connect(provider) const linkDetails:{ chainId: chainId, tokenAddress: [ERC1155 token address], tokenAmount: 1, tokenType: 3, // 3 is for ERC1155 tokens tokenId: [NFT tokenID] } const password = await peanut.getRandomString(16) const preparedTransactions = await peanut.prepareDepositTxs({ address: wallet.address, linkDetails, passwords: [password], }) const transactionHashes: string[] = [] for (const unsignedTx of preparedTransactions.unsignedTxs) { const convertedTx = peanut.peanutToEthersV5Tx(unsignedTx) const signedTx = await wallet.sendTransaction(convertedTx) transactionHashes.push(signedTx.hash) } const { links } = await peanut.getLinksFromTx({ linkDetails, passwords: [password], txHash: transactionHashes[transactionHashes.length - 1], }) return links[0] } createLink().then((link) => console.log(link))