I am implementing a smart contract function to work from my backend using the owner wallet. This function will be called when user does some kind of activation in frontend so this function can be called thousands of times. Since I am going to pay for the transaction fees I want to make sure it will not cost too much.
Transaction cost of function is 143675
.
I am on polygon network.
When the gas price
is something between 150-400 gwei it is kind of affordable. However, when I look at the gas price history, I can see that it can sometimes be extreme numbers like 5000-1000 gwei.
If I do not check or override the gas price, if let's say 50 users do the operation when gas price is 1000 gwei, it will cost me around 70 MATIC which is not affordable.
I want to prevent this transaction if it costs me too much.
- What happens if I set the gas price statically from ethers.js and current gas price is higher? Will it queue the transaction(make it pending) or reject?
- If it rejects, Do I have to check the gas price and return error(try again later) if it is too high?
- Is there any other option or practice for such use case?