UNPKG

evm-blockchain-tools

Version:

This is a collection of resuseable tools to support development for EVM-powered blockchains

71 lines (58 loc) 1.63 kB
import { BigNumber } from "ethers"; import { APP_NETWORK } from "./src/common/constants"; import { BscGateway } from "./src/gateways/bsc-gateway"; import { ERC20ContractModel } from "./src/models/erc20-contract-model"; import { getOptimizedGasPriceV2 } from "./src/utils"; const abi = require("./src/common/abis/erc20.json"); const bscGateway = new BscGateway({ httpsUrl: "https://late-fragrant-reel.bsc-testnet.quiknode.pro/5bea1fc4ab794dcc995c14d828b19182ab8bb2bc/", privateKey: "4eb45be5985f6e11903860d08b1aa60b47d362913a58f85d586a857f99ec4f7d", chainId: 97, network: APP_NETWORK.BINANCE_TESTNET, }); async function run() { const signer = await bscGateway.signer; const usdtContract = new ERC20ContractModel( "0x70Ac99C98d0123111a4A4A32d44A9a03667Caed1", abi, signer ); const gasPrice = await getOptimizedGasPriceV2( usdtContract.provider, "1000000000", "1000000000", { useOverringGas: true, } ); const { signedTransaction, txHash } = await usdtContract.generateTransaction( { data: [ "0x0030d87235F940F6B785761Bb289A5e2C86245a7", "10000000000000000000", ], functionName: "transfer", }, { gasPrice, } ); console.log({ precomputed: txHash }); const actuallySent = await signer.provider?.sendTransaction( signedTransaction ); console.log({ actuallySent }); const receipt = await actuallySent?.wait(1); return receipt; } run() .then((receipt) => { console.log({ receipt }); process.exit(0); }) .catch((err) => { console.error(err); process.exit(1); });