Skip to content

Instantly share code, notes, and snippets.

@kricha
Created January 17, 2023 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kricha/0f80094660d2382fab32c5c597314c73 to your computer and use it in GitHub Desktop.
Save kricha/0f80094660d2382fab32c5c597314c73 to your computer and use it in GitHub Desktop.
import Web3 from 'web3';
import { TransactionConfig } from 'web3-core';
import BigNumber from 'bignumber.js';
const web3 = new Web3('https://goerli.infura.io/v3/c057675750ad44839fb0239fb6229158');
const contract = await new web3.eth.Contract(
[
{
inputs: [],
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [
{
internalType: 'contract IERC20',
name: '_token',
type: 'address',
},
{
internalType: 'address[]',
name: '_recipients',
type: 'address[]',
},
{
internalType: 'uint256[]',
name: '_amounts',
type: 'uint256[]',
},
],
name: 'execute',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
],
'0x8698c00b106c9a970baf487de820d485bedcbc73'
);
const from = '0xCc7bfa2cca12DD4f78c54383c1F71795952FB497';
// const trans = contract.methods
// .execute(
// '0x79C950C7446B234a6Ad53B908fBF342b01c4d446',
// ['0xcc7bfa2cca12dd4f78c54383c1f71795952fb497', '0xcc7bfa2cca12dd4f78c54383c1f71795952fb497'],
// [1, 1]
// )
// .send({ from: '0xCc7bfa2cca12DD4f78c54383c1F71795952FB497' });
web3.eth.getTransactionCount(from, 'latest').then(async (nonce) => {
const contractMethod = contract.methods.execute(
'0x79C950C7446B234a6Ad53B908fBF342b01c4d446',
['0xcc7bfa2cca12dd4f78c54383c1f71795952fb497', '0xcc7bfa2cca12dd4f78c54383c1f71795952fb497'],
['10000000', '1000000']
);
// contractMethod.estimateGas({ from }).catch(console.log);
// const gas = BigNumber(await contractMethod.estimateGas({ from }));
const gas = BigNumber(300000);
const block = await web3.eth.getBlock('latest');
const maxPriorityFeePerGas = BigNumber(web3.utils.toWei('1.5', 'gwei'));
// await contract.methods.approve()
const transaction = {
from,
// @ts-ignore: dasdasdas
to: contract._address,
value: '0x0',
maxFeePerGas: BigNumber(block.baseFeePerGas).times(1.5).dp(0).plus(maxPriorityFeePerGas).toString(),
maxPriorityFeePerGas: maxPriorityFeePerGas.toString(),
nonce,
gas: gas.toNumber(),
gasLimit: gas.times(1.5).toNumber(),
data: contractMethod.encodeABI(),
// type: '0x2',
} satisfies TransactionConfig;
console.log({ transaction });
web3.eth.accounts
.signTransaction(transaction, '***')
.then((signedTx) => {
console.log({ signedTx });
return web3.eth.sendSignedTransaction(signedTx.rawTransaction);
})
.then((value) => {
console.log(value);
})
.catch((error) => {
console.log({ error });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment