Overview
These functions provide a high-level API for interacting with the TornadoPool contract. They handle proof generation, merkle tree construction, and transaction submission. Source Location:src/index.js
Functions
buildMerkleTree
Ethers.js contract instance of TornadoPool
MerkleTree - A fixed-merkle-tree instance containing all commitments
Process:
- Queries all NewCommitment events from block 0
- Sorts events by index
- Extracts commitment hashes
- Constructs merkle tree using Poseidon hash function
src/index.js:11
prepareTransaction
Ethers.js contract instance of TornadoPool
Array of input UTXOs to spend (1-16 UTXOs). Will be padded with dummy UTXOs if needed.
Array of output UTXOs to create (1-2 UTXOs). Will be padded with dummy UTXOs if needed.
Relayer fee in token wei. Goes to the relayer address.
Withdrawal recipient address (for withdrawals only, set to 0 for pure transfers)
Relayer address to receive fees
If true, withdraws to L1 via OmniBridge
Fee for L1 execution (only for L1 withdrawals)
Promise<{ args, extData }>
Proof structure to pass to contract:
proof- ZK-SNARK proof bytesroot- Merkle tree rootinputNullifiers- Array of nullifier hashesoutputCommitments- Array of commitment hashespublicAmount- Public amount fieldextDataHash- Hash of external data
External data structure:
recipient- Withdrawal recipientextAmount- External amount (positive for deposits, negative for withdrawals)relayer- Relayer addressfee- Relayer feeencryptedOutput1- Encrypted first outputencryptedOutput2- Encrypted second outputisL1Withdrawal- L1 withdrawal flagl1Fee- L1 execution fee
- Error if inputs length > 16 or outputs length > 2
src/index.js:100
transaction
Ethers.js contract instance of TornadoPool
All other parameters from
prepareTransaction (inputs, outputs, fee, etc.)Promise<TransactionReceipt> - Ethers.js transaction receipt
Process:
- Calls
prepareTransactionto generate proof - Calls
tornadoPool.transact(args, extData)with gas limit of 2M - Waits for transaction confirmation
- Returns transaction receipt
src/index.js:142
registerAndTransact
Ethers.js contract instance of TornadoPool
Account object with:
owner(address) - Account owner addresspublicKey(bytes) - Public key for receiving notes
All other parameters from
prepareTransactionPromise<void> - Resolves when transaction is confirmed
Process:
- Calls
prepareTransactionto generate proof - Calls
tornadoPool.registerAndTransact(account, args, extData) - Waits for transaction confirmation
src/index.js:154
Transaction Types by Parameters
- Deposit
- Transfer
- Withdrawal
- L1 Withdrawal
Deposits add funds to the pool from an external account.
- No inputs (empty array)
- Outputs define how much to deposit
extAmount= sum of outputs (positive)- Must approve tokens before calling
Input/Output Padding: The library automatically pads inputs to 2 or 16 and outputs to 2 using dummy UTXOs with zero amount. You don’t need to manually add dummy UTXOs.