Creating a Link that holds funds is easy. Have a look here how you can create one yourself!
There are two ways of creating a Link. If you are using EthersV5, you can simply call one SDK function to create a Link. If you are not using EthersV5, or want to have more control over the Link creation process, you can call a set of SDK functions.
Create a Link using EthersV5
The 'one function' approach requires you to pass in an EthersV5 signer, together with some basic information of the Link.
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'asyncfunctioncreateLink():Promise<string|null> {let wallet =Wallet.fromMnemonic(mnemonic)constprovider=awaitgetDefaultProvider(chainId) wallet =wallet.connect(provider)const { link,txHash } =awaitpeanut.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, } })return link}createLink().then((link) =>console.log(link))
Create a Link using Signer Agnostic Functions:
You're not using EthersV5, but some other signing library (viem, web3js, wagmi, inhouse etc)? No problem! You will have to prepare the transactions(s), submit the transaction with your wallet, and use the resulting transaction hash to generate the link. The following is an example that does not use a particular signer.
constchainId='11155111'// Sepoliaconstmnemonic='announce room limb pattern dry unit scale effort smooth jazz weasel alcohol'asyncfunctioncreateLink():Promise<string|null> {let wallet =Wallet.fromMnemonic(mnemonic)constprovider=awaitgetDefaultProvider(chainId) wallet =wallet.connect(provider)constlinkDetails= { chainId: chainId, tokenAmount:0.001, tokenType:0,// 0 for ether, 1 for erc20, 2 for erc721, 3 for erc1155 tokenDecimals:18, }constpassword=awaitpeanut.getRandomString(16)constpreparedTransactions=awaitpeanut.prepareDepositTxs({ address:wallet.address, linkDetails, passwords: [password], })consttransactionHashes:string[] = []for (constunsignedTxofpreparedTransactions.unsignedTxs) {constconvertedTx=peanut.peanutToEthersV5Tx(unsignedTx)constsignedTx=awaitwallet.sendTransaction(convertedTx)transactionHashes.push(signedTx.hash) }const { links } =awaitpeanut.getLinksFromTx({ linkDetails, passwords: [password], txHash: transactionHashes[transactionHashes.length-1], })return links[0]}createLink().then((link) =>console.log(link))