Sorry for the late response. I don’t hang out here very often.
Let me clarify something a bit.
Gas price and quantity of gas are two different things.
Say you want to put a galon of gas in your car.
– A Galon will be a galon today, tomorrow, the day after tomorrow.
– The price of the gas, that one might change according to supply and demand.
In the EVM (Ethereum virtual machine) is the same.
– The amount of gas your function consumes will be always the same.
– The amount you are willing to pay per gas (galon of gas) varies.
In the code below:
gas:400000 //(this is the quantity of gas)
gasPrice:web3.utils.toWei(“1”, “gwei”) //(this is the price of the gas)
The quantity of gas should not change, since the amount of work the EVM is doing is the same. So this you can leave the same.
The price, is the one that you need to change, the price of 1 gwei was OK when I made this project and for the network I demoed, which was not avalanche. This is the one that you need to adjust.
As you might have suspected by now, you were trying to put more gas in the car, when the guy in the gas station was telling you, hey buddy, you have not even enough to buy one galon here.
1 - Try by merely commenting the gas and the gas price lines. (I don’t recall very well how the web3 instance in the cloud code works with this so I hardcoded them), it might be possible that the web3 environment in the cloudcode or in the js file will calculate this values for you in the current network.
- If the above doesn’t work try to just increase the price check in https://testnet.snowtrace.io/ the price of gas in Fuji network for the latest transaction.
At the moment of writing this comment is around 104 nAVAX (Gwei) quite more expensive than the 1 gwei that is hardcoded in the function.
By the way, not sure if you have done it but you need to change the chain on which the web3 instance is created. It was matic, you have to change it to fuiji. (I’m assuming you are in the testnet, if not you should, until you get everything tested).
On the error you are seeing, that is related to the limitation of amount of gas in each block. This limits the number of transactions making blocks more lean and easy to manage helping network decentralization. For hardcoded value of gas, return to the first one that was hardcoded.