Below is the code that I'm running. When I entered "gas" and "gasLimit" as the keys, both worked. Why is that? What does "gas" represent? And what is the optimum amount of gasLimit should I use (ethgasstation.info is currently recommending "Gas Used: 21,000").

smartContract.methods.transferFrom(walletAddress, recipientAddress, tokenId.send({
        from: walletAddress,
        gas: 4700000,
}, function (err, transactionHash) {

    if (!err) {
            console.log(transactionHash + " success"); 
    } else {


The gas parameter represents the price which you are willing to pay for each gas unit (it's like a public auction - the higher your price is, the faster your transaction will be executed by one of the miners on the network).

The gasLimit parameter represents the maximum number of gas units that you are willing to allow for your transaction (it is essentially in order to protect yourself, in case your transaction executes some smart-contract function whose code is not known to you for some reason).

The total cost of your transaction will be the gas-price times the actual amount of gas units used.

However, in order for the transaction to even be considered, you must have at least gas * gasLimit wei in the balance of the account with which you are going to execute your transaction.

  • If I don't enter gas price in the transaction, what would be the default value? – warnerque Jul 1 '19 at 12:14
  • @warnerque: I believe that the node takes the average of the last N blocks, or something similar to that (maybe the median of the last N blocks). – goodvibration Jul 1 '19 at 12:17
  • Thanks for your reply. I'm assuming I can use the keyword "gas or "gasPrice" where both mean the same thing? – warnerque Jul 1 '19 at 12:29
  • @warnerque: I've noticed that too, but I'm not sure that it is guaranteed to work in every web3 function out there. Some of them may give you an error on a gasPrice field, and some of them - even worse - may simply ignore it (and you'll have no idea). Same goes for other tools (in our eco-system) which take the gas-price as input. For example, Truffle configuration file, or ganache-cli (though in this case it may actually be the opposite, i.e., this tool expects gasPrice instead of gas). So in short, always refer to the official documentation and use whatever it tells you to use. – goodvibration Jul 1 '19 at 12:34
  • Thanks (again) for the heads-up. – warnerque Jul 1 '19 at 14:00

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.