Skip to content

aii23/BatchedTransactionTest

Repository files navigation

Mina zkApp: Batch_Test

This repository contains code for batching transactions, either by sending multiple transactions in parallel or batching multiple transactions into one.

What's New

  • o1js Patch
    A patch to export getCachedAccount from fetch.js.

  • LocalContext
    A utility for updating the context after executing zkApp methods.

Usage Example

Single Method Call within a Transaction

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);
  }
);

Multiple Method Calls within a Transaction

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
);

How to Run

  1. Install dependencies:

    pnpm install
  2. Configure your zkApp:

    zk config

    Make sure to create a deploy alias.

  3. Deploy your zkApp:

    zk deploy <YOUR_DEPLOY_ALIAS>
  4. 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>

License

This project is licensed under the Apache-2.0 License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors