Use your zkApp
"Cook a Recipe" anonymously with RAILGUN Quickstart
Given a full Recipe and its inputs, RAILGUN Quickstart will generate a zero-knowledge proof and a final serialized transaction for the RAILGUN Relay Adapt contract.
cook-recipe-example.ts
const swap = new ZeroXSwapRecipe(sellERC20Info, buyERC20Info, slippagePercentage);
// Inputs that will be unshielded from private balance.
const unshieldERC20Amounts = [{ ...sellERC20Info, amount }];
const recipeInput = { networkName, unshieldERC20Amounts };
const { populatedTransactions, erc20Amounts } = await swap.getRecipeOutput(recipeInput);
// Outputs to re-shield after the Recipe multicall.
const shieldERC20Addresses = erc20Amounts.map(({tokenAddress}) => tokenAddress);
// RAILGUN Quickstart will generate a [unshield -> call -> re-shield] transaction enclosing the Recipe multicall.
const crossContractCallsSerialized = populatedTransactions.map(
serializeUnsignedTransaction,
)
const {gasEstimateString} = await gasEstimateForUnprovenCrossContractCalls(
...
unshieldERC20Amounts,
...
shieldERC20Addresses,
...
crossContractCallsSerialized,
...
)
await generateCrossContractCallsProof(
...
unshieldERC20Amounts,
...
shieldERC20Addresses,
...
crossContractCallsSerialized,
...
)
const {serializedTransaction} = await populateProvedCrossContractCalls(
...
unshieldERC20Amounts,
...
shieldERC20Addresses,
...
crossContractCallsSerialized,
...
);
// Submit transaction to RPC.
const transaction = deserializeTransaction(serializedTransaction);
await wallet.sendTransaction(transaction);
// Note: use @railgun-community/waku-relayer-client to submit through a Relayer instead of signing with your own wallet.
Last modified 22d ago