I'm trying to estimate gas fees of a contract that I'm about to execute. My code is as follows.
import Web3 from "web3";
const web3 = new Web3();
const estimateGasLimit = async (
fromAddress: string,
outputAddress: string,
amount: number,
gasPrice: number,
gasLimit: number,
chain = 1,
contractAddress: string
) => {
const contract = new web3.eth.Contract(minABI, contractAddress, {
from: fromAddress,
});
return await contract.methods.transfer(outputAddress, amount).estimateGas();
};
I'm testing for USDT right now, whose contract address is '0xdac17f958d2ee523a2206206994597c13d831ec7'. It works perfectly for amount 1000000, which is 1 USDT as the decimal for USDT is 6, but fails for 10000000 that is 10 USDT. I get the following error
UnhandledPromiseRejectionWarning: Error: Returned error: invalid opcode: opcode 0xfe not defined
at Object.ErrorResponse (/home/gaurav/Work/Revamped-Everything/wallet/node_modules/web3-core-helpers/lib/errors.js:28:19)
at /home/gaurav/Work/Revamped-Everything/wallet/node_modules/web3-core-requestmanager/lib/index.js:288:36
at XMLHttpRequest.request.onreadystatechange (/home/gaurav/Work/Revamped-Everything/wallet/node_modules/web3-providers-http/lib/index.js:98:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/gaurav/Work/Revamped-Everything/wallet/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/home/gaurav/Work/Revamped-Everything/wallet/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/home/gaurav/Work/Revamped-Everything/wallet/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/home/gaurav/Work/Revamped-Everything/wallet/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:327:22)
at IncomingMessage.EventEmitter.emit (domain.js:506:15)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
I am very new at ethereum and blockchain, so I would appreciate any help that I could get. Thank you.