"Cook a Recipe" anonymously with RAILGUN Quickstart
Given a full Recipe and its inputs, RAILGUN Wallet SDK will generate a zero-knowledge proof and a final serialized transaction for the RAILGUN Relay Adapt contract.
This final transaction can be submitted to the blockchain by any wallet, including a Relayer.
cook-recipe-example.ts
import { RecipeERC20Info, ZeroXSwapRecipe, RecipeInput, RecipeOutput} from'@railgun-community/cookbook';import { NetworkName,} from'@railgun-community/shared-models';constsellERC20Info:RecipeERC20Info= { tokenAddress:'0x6B175474E89094C44Da98b954EedeAC495271d0F',// DAI decimals:BigInt(18)}constbuyERC20Info:RecipeERC20Info= { tokenAddress:'0xdac17f958d2ee523a2206206994597c13d831ec7',// USDT decimals:BigInt(18)}constslippagePercentage=0.05;constswap=newZeroXSwapRecipe(sellERC20Info, buyERC20Info, slippagePercentage);// Inputs that will be unshielded from private balance.constunshieldERC20Amounts= [ { ...sellERC20Info, amount:BigInt('0x10'),// hexadecimal amount }];constrecipeInput:RecipeInput= { NetworkName.Ethereum, unshieldERC20Amounts };const {crossContractCalls,erc20AmountRecipients,nftRecipients,feeERC20AmountRecipients,minGasLimit,} =awaitswap.getRecipeOutput(recipeInput);// Outputs to re-shield after the Recipe multicall.constshieldERC20Addresses=erc20AmountRecipients.map(({tokenAddress}) => tokenAddress);// RAILGUN Wallet will generate a [unshield -> call -> re-shield] // transaction enclosing the Recipe multicall.const { gasEstimate } =awaitgasEstimateForUnprovenCrossContractCalls(... unshieldERC20Amounts,... shieldERC20Addresses,... crossContractCalls,...)awaitgenerateCrossContractCallsProof(... unshieldERC20Amounts,... shieldERC20Addresses,... crossContractCalls,...)const { transaction } =awaitpopulateProvedCrossContractCalls(... unshieldERC20Amounts,... shieldERC20Addresses,... crossContractCalls,...);// Submit transaction to RPC.awaitwallet.sendTransaction(transaction);// Note: use @railgun-community/waku-relayer-client to submit // through a Relayer instead of signing with your own wallet.