I am using web3.js to send a transaction. This is the code that I have currently:

async function sendTx(tran, ethAddress, privateKey, value=0) {
    var tr = {
        chainId: await web3.eth.getChainId(),
        gas: 300000,
        nonce: await web3.eth.getTransactionCount(ethAddress),
        value: web3.utils.toWei(value, 'ether'),
        data: tran.encodeABI()

    try {
        tr.gas = await web3.eth.estimateGas({
            from: ethAddress
    } catch {
        console.error('Could not estimate gas');
    var signedTx = await web3.eth.accounts.signTransaction(tr, privateKey);

var sc = new web3.eth.Contract('abi', 'contract address');
await sendTx(sc.methods.someMethod('param1'), 'ETH address', 'privateKey');

If I run it, I get the following error:

Uncaught (in promise) Error: Signer Error: gas limit is too low. Need at least 53204

If I remove data: tran.encodeABI(), everything works fine.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.