Welcome to Dev3
Search
K

Out of gas error

A common error when running a live example, or interacting with the blockchain, is the one where you get an "out of gas exception". The ones experienced with blockchain will understand what this means. For every blockchain transaction, you need to pay for its execution. The gas is paid in the native coins for the given blockchain network with which you interact with.
If you are interacting with the Polygon network, the native coin is called MATIC token, and you need to own these in order to pay for the transactions. For Ethereum blockchain network gas token is called ETH, for Avalanche this is AVAX, and so on... MATIC tokens, as any other, have their market price, and at the time of writing it's around $1.25 / MATIC which is enough to execute a bunch of transactions.
But for testing purposes, it's best to test the transactions on the test chains. For example, Polygon runs a test blockchain network called Polygon Mumbai, and you have to pay for the transaction execution in the Mumbai's MATIC token, but the difference here's that price of the test MATIC coin is 0.
If you're running our live examples, they are all deployed and connected to the Mumbai Test chain. So if you get an out of gas error such as the one below, it means you need to obtain test MATIC coins.
Out of gas error when executing the transaction.
You can see here that the error clearly states you're out of "gas", gas being the native coin with which you need to pay for the transaction. In the upper-left, the gas available is equal to zero. So again, if you're running Live Examples from the docs here, or you are trying to interact with your own contracts and examples deployed on the Mumbai Test Chain, you can simply copy your blockchain address (marked with an arrow in the image above) and go to the Polygon Faucet Portal to obtain some of the test gas tokens. Paste your address in the Wallet Address field on the portal and then click on the 'Submit' request. Then again confirm the faucet action and that's it, your wallet will be funded with the test tokens in 5 or 10 seconds. Now go back to the transaction execution screen and try repeating the action.