Skip to content

Instantly share code, notes, and snippets.

@CoolCatsNFTPublic
Last active December 30, 2021 20:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CoolCatsNFTPublic/5ab5e71444637fde9911f046130870ee to your computer and use it in GitHub Desktop.
Save CoolCatsNFTPublic/5ab5e71444637fde9911f046130870ee to your computer and use it in GitHub Desktop.
Estimating gas for a transaction
// 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
};
@CoolCatsNFTPublic
Copy link
Author

NOTE:
This is WIP code from our dev server. Always do your own testing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment