How can I manually add gas price and gas limit in ethers using async function

const gas = async () => {

const ethers = Moralis.web3Library;

const web3Provider = await Moralis.enableWeb3();

const gasPrice = await web3Provider.getGasPrice();

const signer = web3Provider.getSigner();

const contract = new ethers.contract(“0xdAC17F958D2ee523a2206206994597C13D831ec7”, ABI, signer);

const transaction = await contract.approve({

_spender: “0xc…”,

_value: 1,

gasLimit: 10000000,

gasPrice: gasPrice,

// nonce: nonce || undefined,

});

await transaction.wait();

};

Please here is my code

Error message I keep getting

this may help you related to that error message:

Thus worked fine, thanks @cryptokid

1 Like

Please I’m still getting the “cannot estimate gas” error, please help

where from is this gas limit?

on what network it is?

I copied the gasLimit from an example.
I’m using ethereum network

what are you trying to do there?

try to do some debugging, you may also need ETH to run that transaction

I’m trying to manually add gas price cuz of the error message I’ve been having, but don’t know how to go about it. Yea I do have eth to run the transaction.
I just need the right code to implement the gas price

main
Here is the error I have been getting

you could get that error for various reasons, like contract exception, not enough eth, high gas limit

I have got enough eth, and I’m calling usdt contract functions

you could try it on a test network too, that gas limit doesn’t seem right for me, look at some transactions that are on chain to see what is the expected gas value for that transaction

please can you paste the correct code with async function on how to go about it, please. I’ve been on this for a long time.

I’m sure that you will find examples online, you can do it directly with web3 or ethers, I don’t understand what is the connection with async in particular

whenever i make you of await function, i get the error message of me using async function, i’m new to this

you have to define the function as async, if you use await inside that function

i have tried alot of codes i,ve found online, but i keep getting the same error message

i check other networks gasLimit and added it to mine, the error still showed

try to look at a transaction that is on chain, or make a transaction on chain with metamask, look at the parameters for that transaction