npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

blockbatch

v1.0.10

Published

SDK for sending multiple transactions of ETH and ERC20 token transfers in a single batch transaction

Downloads

6

Readme

BlockBatch SDK

BlockBatch SDK is used for sending multiple ETH and ERC20 tokens in a single Batch Transaction.

Docs

Read further about SDK classes and methods here

Demo

Try out the SDK demo in this code sandbox

Installation

npm i blockbatch

Import

Sample use of the SDK

import { BatchTransaction } from "blockbatch";

const batchSender = new BatchTransaction();
const init = await batchSender.init();

Sending Batch Transaction

Creating ETH/ERC20 Batch data

To create a batch transaction data for just ETH transfers, provide the recipient address and amount to transfer, without any tokenAddress.

// ETH transactions
const batchData: BatchData[] = [
    {
      recipient: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
      amount: "0.01"
    },
    {
      recipient: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
      amount: "0.02"
    },
]

If tokenAddress is provided the transaction is going to be considered for ERC20 batch by the SDK.

// ERC20 transactions
const batchData: BatchData[] = [
      {
        recipient: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
        amount: "1000000",
        tokenAddress: "0x857616Fbc511212A2a848dA64B4fC3b9678af6F9"
      },
      {
        recipient: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
        amount: "10",
        tokenAddress: "0x857616Fbc511212A2a848dA64B4fC3b9678af6F9"
      }
  ];

You can add all of your ETH/ERC20 transactions in a single BatchData array. The SDK handles to process them in a single batch internally.

const batchData: BatchData[] = [
      // ETH transaction
      {
        recipient: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
        amount: "0.01",
      },
      // ERC20 transaction
      {
        recipient: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
        amount: "10",
        tokenAddress: "0x857616Fbc511212A2a848dA64B4fC3b9678af6F9"
      }
  ];

[!IMPORTANT] Users should understand the type of amount they are passing for the transaction in the batch. Amount of ETH passed in BatchData has the unit of ether and not wei or gwei. And the amount of ERC20 tokens to send should be formatted according to the number of decimals that token has. Example - Amount 10 in ETH batch means sending 10 ether. Amount 10 in ERC20 batch means sending 10*(1e(-18)) ERC20 tokens. (ERC20 tokens have 18 decimal places by default).

Call the processBatchTransactions() and pass it the batchData to execute the transactions prepared.

const response = await batch.processBatchTransactions(batchData);
console.log(`Transaction response ${response?.txn}`);

[!NOTE] The response object can contain data of the type of { txn: ethers.TransactionResponse, invalidTxns: InvalidTransactions[] } or just InvalidTransactions[]. The invalid transactions array contains the data of those transactions in the processed batch which are invalid. So even if 3 out of 10 transactions might have error in them, the valid 7 transactions will execute.

System Support

The SDK will support both client-side and backend integrations depending on the arguments provided to the batchSender.init() function.

If the browser window contains the ethereum object, meaning if your browser contains a wallet extension like Metamask, then you don't have to provide any arguments to batchSender.init() function. You will be prompted to connect your account internally via the SDK.

If you are already connected to your wallet in your dapp, to prevent the above behaviour of the SDK, pass either the signer object or private_key (along with provider) to batchSender.init().

Example: If dapp already has signer -

const signer: ethers.Signer = {...}; // signer object
await batchSender.init(signer);

Or private key along with provider

const provider: ethers.JSONRpcProvider = {...}; // provider object
const PRIVATE_KEY = "0x..."
await batchSender.init(PRIVATE_KEY, provider);

The above example code snippets are the only way to use SDK in a Node (backend) environment.

[!WARNING] Its always better to not share your private key. The SDK doesn't store any of the keys. It will always be better to use the signer object generated and passed in the SDK (if required).

Constants

  • Batch Transfer Contract - 0x7FD154df41ec41336A86Ee53a3F7Fe886E80Efc7
  • Parent Batching Contract - 0xb8cBB6a9965A851Dcb88Bb1734231c531a0bcdF1

Smart Contracts used Repository - https://github.com/aditya172926/batching_eth_contract

Smart Contracts are deployed on Ethereum Sepolia Testnet

Smart contracts

Verified on Blockscout