Last active
December 30, 2021 20:50
-
-
Save CoolCatsNFTPublic/5ab5e71444637fde9911f046130870ee to your computer and use it in GitHub Desktop.
Estimating gas for a transaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the estimated gas from the adopt method | |
try { | |
methodGasPrice = await this.contract.methods.adopt(adoptNum).estimateGas({ | |
value: price, | |
from: account | |
}); | |
} catch (err) { | |
console.log("ERROR Method Gas Price"); | |
} | |
try { | |
currentGasPrice = await this.web3.eth.getGasPrice(); | |
} catch (err) { | |
console.log("ERROR Current Gas Price"); | |
} | |
// Buffer gas with a value that makes sense for your project | |
// has pros and cons - always do your own research | |
const sendTransactionData = { | |
// increase the gas limit | |
gas: parseInt(1.13 * methodGasPrice), | |
// increase the gas price | |
gasPrice: parseInt(1.13 * currentGasPrice), | |
from: account, | |
value: price | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE:
This is WIP code from our dev server. Always do your own testing :)