Want to create a raffle to engage your community? Here is how you can!
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 getRaffleLinkFromTxfunction. Please make sure to request for an API Key here.
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.01,// Total amount of the raffle tokenType:0,// 0 for ether, 1 for erc20, 2 for erc721, 3 for erc1155 tokenDecimals:18, }constnumberOfLinks=5constpassword=awaitpeanut.getRandomString(16)constprepareTxsResponse=awaitpeanut.prepareRaffleDepositTxs({ userAddress:wallet.address, linkDetails, password, withMFA:false, numberOfLinks: numberOfLinks, })consttransactionHashes:string[] = []for (constunsignedTxofprepareTxsResponse.unsignedTxs) {constconvertedTx=peanut.peanutToEthersV5Tx(unsignedTx)constsignedTx=awaitwallet.sendTransaction(convertedTx)transactionHashes.push(signedTx.hash) }constgetRaffleLinkResponse=awaitpeanut.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. })returngetRaffleLinkResponse.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!