When I sign and send raw transactions with web3 in javascipt , to call a method from Smart Contract, I always pass the transaction gas variable after getting it with estimateGas function, from Smart Contract method, as following:

mySmartContract= new web3.eth.Contract(SmartContractABI, SmartContractAddress);
mySmartContract.methods.set(inputnum).estimateGas({from: miAddress})
          tx.gas = web3.utils.toHex(gas);
        console.log("Set() - catch error");

How could I do the same to invoke the fallback function from the Smart Contract? estimateGas() is a function from "methods" object, but "fallback" is not a method.

Thanks in advance


After some research & testing I found the solution by mysef. As a fallback function is unnamed, I just need to use estimateGas with the "eth" object to get the gas stimation of the default function (fallback):

const web3eth = require('web3-eth');
const eth = new web3eth('https://ropsten.infura.io/v3/XXXXXXX');
var tx = {};

      from: miAddress
    .then(function(gas) {
      tx.gas = web3.utils.toHex(gas);
    .catch(function(error) {
      console.log("Estimategas() - catch error");


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.