question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I set a manual gas price for a contract calling a function? And is nonce management implicit?

See original GitHub issue

I have created a contract object with ethers.Contract giving it ABI and address. My necessity is to set a gas price that is constant so that I can do the transaction with lower fees. The problem is I cant find a way to set my gas price.

var provider = new ethers.providers.InfuraProvider('ropsten');
const privateKey1 = Buffer.from(process.env.PRIVATE_KEY_1,'hex')
var wallet = new ethers.Wallet(privateKey1,provider)
wallet = wallet.connect(provider)
......
var contract = await new ethers.Contract(address, originStampABI, wallet);
for(let hash of hashes){

	var sendTransactionPromise =  await contract.submitHash(hash)
        sendTransactionPromise.gasPrice = 20000000000
	sendTransactionPromise.gasLimit = gasLimit
	console.log(sendTransactionPromise)
	/* sendTransactionPromise.then(function(tx) {
		console.log(tx);
}); */
}
}

I could only find the way to set the gas price by calling the gas price below the smart contract function call which seems to not work and give default gas price of 1GWEI in etherscan. I am using infura as the provider Also is nonce management implicit in ethers.js. I have not specified any nonce but it seems to be working

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yuetloocommented, Jun 26, 2020

@sssubik , by default, if you don’t override the nonce, ether.js will populate that for you by querying the transaction count from the network. But, if you want to use loop, try the experimental package, NonceManager, it increments the nonce for you.

1reaction
yuetloocommented, Jun 26, 2020

@sssubik , use the override parameter, see doc here and overrides properties here

    var overrides = {
        gasPrice: 20000000000
    };

    var sendTransactionPromise =  await contract.submitHash(hash, overrides)
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Nonce, Gas Price and Gas Limit?
A nonce is the number of the transaction of the sender's address. Every transaction from an address is numbered sequentially, beginning with 0...
Read more >
foundry/README.md at master - forge - GitHub
Foundry will show you a comprehensive gas report about your contracts. It returns the min , average , median and, max gas cost...
Read more >
Ethereum Gas: How to set gas price & gas limit in transactions?
FREE TRAININGS (WEB3 DEV, FLASH LOANS...) How to find your first 6-Figures Blockchain Developer Job: https://bit.ly/390ebTq Learn how to ......
Read more >
Contracts — Solidity 0.8.17 documentation
Functions can be defined inside and outside of contracts. Functions outside of a contract, also called “free functions”, always have implicit internal ...
Read more >
Solidity Documentation - Read the Docs
by calling functions of the code that manages the database. ... The gas price is a value set by the originator of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found