Batch Transaction

Combine multiple transactions and make them atomic

Introduction

With Blocto, you can combine multiple transactions into a single transaction for the following advantages:

  1. Save gas fee

  2. Make multiple transactions atomic, so they either all succeed or all fail

Usage

There are two ways to combine transactions:

import Web3 from 'web3';

// Use the Ethereum provider injected by Blocto app
const txHash = await window.ethereum.request({
  method: 'blocto_sendBatchTransaction',
  params: [
    web3.eth.sendTransaction.request(SOME_REQUEST),
    web3.eth.sendTransaction.request(SOME_OTHER_REQUEST)
  ]
})

console.log(txHash) // ex: 0x12a45b...

B. Web3 Batch Request

Example

For example, if you are building a campaign for PoolTogether. You want to let user claim a DAI token from a smart contract, approve PoolTogether from spending user's DAI and deposit the DAI into PoolTogether, you can do something like:

A. EIP-1193

B. Web3 Batch Request

For more information about batch transactions, check out web3.js documentation.

Last updated

Was this helpful?