Creating a Raffle Link can look similar to the previous Link creation processes. You can use either EthersV5 as a signer or a different library, and you'll need an API Key to use getRaffleLinkFromTx
***function. Please make sure to request for an API Key h*ere.
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 createLinks(): Promise<string> {
let wallet = Wallet.fromMnemonic(mnemonic)
const provider = await getDefaultProvider(chainId)
wallet = wallet.connect(provider)
const linkDetails = {
chainId: chainId,
tokenAmount: 0.01, // Total amount of the raffle
tokenType: 0, // 0 for ether, 1 for erc20, 2 for erc721, 3 for erc1155
tokenDecimals: 18,
}
const numberOfLinks = 5
const password = await peanut.getRandomString(16)
const prepareTxsResponse = await peanut.prepareRaffleDepositTxs({
userAddress: wallet.address,
linkDetails,
password,
withMFA: false,
numberOfLinks: numberOfLinks,
})
const transactionHashes: string[] = []
for (const unsignedTx of prepareTxsResponse.unsignedTxs) {
const convertedTx = peanut.peanutToEthersV5Tx(unsignedTx)
const signedTx = await wallet.sendTransaction(convertedTx)
transactionHashes.push(signedTx.hash)
}
const getRaffleLinkResponse = await peanut.getRaffleLinkFromTx({
linkDetails,
password: password,
txHash: transactionHashes[transactionHashes.length - 1],
numberOfLinks: numberOfLinks,
APIKey: '', // Request an api key
withCaptcha: false,
withMFA: true, // for double-claim prevention. Talk to us if you want to know more.
})
return getRaffleLinkResponse.link
}
createLinks().then((link) => console.log(link))
We also support MFA and captcha, as well as multiple tokens in one raffle. Get in touch via Telegram or Discord to find out how!