Skip to content

Instantly share code, notes, and snippets.

@weeravit
Last active September 5, 2022 17:00
Show Gist options
  • Select an option

  • Save weeravit/a923e591bcbb45399c6ae7c21c673283 to your computer and use it in GitHub Desktop.

Select an option

Save weeravit/a923e591bcbb45399c6ae7c21c673283 to your computer and use it in GitHub Desktop.
[Solidity] EtherJs execute smart-contract
require('dotenv').config();
const { ethers } = require("ethers");
const BigNumber = require('bignumber.js');
const multisendContractABI = require('./contract.abi.json');
const provider = new ethers.providers.JsonRpcProvider(process.env.PROVIDER_URL);
const walletPrivateKey = process.env.WALLET_PRIVATE_KEY;
const signer = new ethers.Wallet(walletPrivateKey, provider);
const multisendContractAddress = '0xe7dEfEC58f2e9C8B91aFB565c052d1bfa41d619d';
const multisendContract = new ethers.Contract(multisendContractAddress, multisendContractABI, signer);
async function multiTransfer(addressList = [], amount) {
const totalAmount = BigNumber(amount).multipliedBy(addressList.length).toNumber();
const etherOfTotalAmount = ethers.utils.parseEther(`${totalAmount}`);
const etherOfAmountPerAddress = ethers.utils.parseEther(`${amount}`);
const options = {value: etherOfTotalAmount};
await multisendContract.multiTransfer_OST(addressList, etherOfAmountPerAddress.toNumber(), options);
console.log('---Transfer Success---');
}
multiTransfer(
['0x6DeAc824BF8EDB444c00dF2e4aE40369b89db95E', '0x37C424d4B70c576E76DA94e5f6fAe6E700961300'],
0.0005 // 0.0005 BNB
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment