ethers-multisend-package
v1.0.15
Published
A package to handle multi-send transactions on Ethereum.
Downloads
18
Readme
Ethers Multisend Package
The ethers-multisend-package
enables the execution of batch transactions on the Ethereum network utilizing the ethers.js
library. This package supports batching operations for Ether, ERC20 tokens, and generic function calls. It also includes utilities for token allowance checks, approvals, and gas estimation.
Installation
To use this package, first install it via npm:
npm install ethers-multisend-package
Configuration
Before using the batch execution functions, create a config file for ease of use and configure the network and contract details:
import { ethers } from 'ethers';
interface Config {
networkUrl: string;
contractAddress: string;
}
const config: Config = {
networkUrl : "https://virtual.mainnet.rpc.tenderly.co/8c916c79-0c6d-4245-b325-447fb811862e",
contractAddress: '0xCD4030d7e7Cb295D3f227A175DBa01dD1988F45B',
};
const provider = new ethers.JsonRpcProvider(config.networkUrl);
export { config, provider };
Note: You can deploy your own contract and replace the contract address with your own or use the one provided in the config.ts file.
Usage
To execute batch transactions, prepare an array of transactions, a signer, and optionally, gas options. Use the following function to execute them:
function executeBatchTransactions(
transactions: Transaction[],
signer: ethers.Signer,
gasOptions?: GasOptions
): Promise<ethers.TransactionResponse> {}
Transaction arry look like this
interface Transaction {
type: "ETH" | "ERC20";
to: string;
amount: string;
tokenAddress?: string;
decimals?: number;
}
Allowance Manager
For checking allowance, approvance you can use our setTokenAllowance and checkTokenAllowance functions respectively
export async function setTokenAllowance(tokenAddress: string, amount: string, signer: ethers.Signer): Promise<void> {}
export async function checkTokenAllowance(tokenAddress: string, ownerAddress: string, signer: ethers.Signer): Promise<string> {}
Gas Estimation
Gas estimation is handled by the estimateGas function in the gasEstimation.ts file. You can use it by providing the signer and transaction request:
import { estimateGas } from './gasEstimation';
const estimatedGas = await estimateGas(signer,transactionRequest);
Example
Here is an example of how you can use the package to execute batch transactions:
const transactions = [
{
type: "ETH",
to: "0x1234567890abcdef1234567890abcdef12345678",
amount: "0.5",
},
{
type: "ERC20",
to: "0xabcdef1234567890abcdef1234567890abcdef12",
amount: "100",
tokenAddress: "0xdeadbeef1234567890abcdef1234567890abcdef",
decimals: 18
}
];
const signer = new ethers.Wallet('<privateKey>', provider);
or
const signer = new ethers.BrowserProvider(window.ethereum);
const gasOptions = {
gasPrice: ethers.parseUnits('10', 'gwei'),
gasLimit: 1000000
};
if you dont give gasOptions it will be estimated automatically by
const estimatedGasLimit = await estimateGas(signer,transactionRequest);
const estimatedGas = await estimateGas(signer,transactionRequest);
const result = await executeBatchTransactions(transactions, signer, gasOptions);