This repository contains code for batching transactions, either by sending multiple transactions in parallel or batching multiple transactions into one.
-
o1js Patch
A patch to exportgetCachedAccountfromfetch.js. -
LocalContext
A utility for updating the context after executing zkApp methods.
let context = await LocalContext(zkApp.address);
let tx1 = await context.transaction(
{ sender: feepayerAddress, fee, nonce: nonce++ },
async () => {
let curValue = zkApp.num.get();
await zkApp.update(curValue);
}
);
let tx2 = await context.transaction(
{ sender: feepayerAddress, fee, nonce: nonce++ },
async () => {
let curValue = zkApp.num.get();
await zkApp.update(curValue);
}
);let updaters = [];
for (let i = 0; i < NUM_OF_TRANSACTIONS; i++) {
updaters.push(() => {
let currentValue = zkApp.num.get();
return zkApp.update(currentValue);
});
}
const batchedTransaction = await context.batchedTransaction(
{ sender: feepayerAddress, fee, nonce: nonce++ },
updaters
);-
Install dependencies:
pnpm install
-
Configure your zkApp:
zk config
Make sure to create a deploy alias.
-
Deploy your zkApp:
zk deploy <YOUR_DEPLOY_ALIAS>
-
Test the batching:
-
Test with multiple transactions sent in parallel:
node ./build/src/interact.js <YOUR_DEPLOY_ALIAS>
-
Test with batched transactions:
node ./build/src/interact_batched.js <YOUR_DEPLOY_ALIAS>
-
This project is licensed under the Apache-2.0 License.