🥜
Peanut Docs
  • Learn
    • 🥜What is Peanut?
    • 🏦Cashout
      • Supported geographies
    • 📩How to use Peanut Links?
      • ⚙️How do Peanut Links Work?
      • 🔒Trust assumptions
    • 📌Use cases
    • 📚Case Studies
      • 🎁Welcome Packs
      • 📘Raffles to Boost UWAs and Transactions
      • 📗Sending Testnet Tokens at Hackathons
      • 📙IRL Events Marketing
    • ⛓️Supported Chains and Tokens
    • 💰Pricing
    • 🆘Support
  • Integrate
    • Using the SDK
      • Create ClaimLinks
        • Create Link
        • Batch Create Links
        • Create Raffle Links
        • Create Multi-Token Link
        • Create NFT Link
        • Create Gasless Links
        • Create Branded Links
      • Claim
        • Claim Link
        • Claim Gasless Link
        • Claim Cross-Chain Link
        • Claim Raffle Link
        • Claim Link as Sender (Reclaiming)
      • Create Request Link
      • Pay a Request Link
      • Pay a Request Link X-Chain
      • Utils
        • Get Link Details
        • Cross-chain
          • Get Supported Destination Chains
          • Get Supported Destination Tokens
          • Get Cross-Chain Options
          • Get Cross-Chain Route
        • Raffle (Legacy)
          • Get Raffle Info
          • Get User Raffle Status
          • Get Raffle Leaderboard
        • Get Default Provider
        • Get Supported Peanut Chains
        • Toggle Verbosity
        • EthersV5 <> Peanut Transaction Types
        • Estimate Fee Options
        • Get Random String
        • Get all deposits for an Address
        • Get Token Balance
      • API Keys
      • White-Labelling
      • Troubleshooting
      • SDK FAQ
    • Embedding an IFrame
    • Integrate Directly in Smart Contracts
    • Wallet Integrations
      • 🎬UI Examples
  • Other
    • 👾Bug bounties
    • 🔓Security Audit
    • 📜Peanut Protocol Contracts
  • BLOGS
    • Transfer Abstraction
    • Can We Sidestep Onchain Identity?
  • Additional Links
    • 🐦Twitter
    • 😊Telegram
    • 🤙Discord
    • 🥜Work with Us
    • 🎨Press Kit
    • 👨‍⚖️Contact and Legal
Powered by GitBook
On this page
  • For ERC721
  • For ERC1155:
  1. Integrate
  2. Using the SDK
  3. Create ClaimLinks

Create NFT Link

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.

import 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.

import 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))
PreviousCreate Multi-Token LinkNextCreate Gasless Links

Last updated 1 year ago