Lessons in Ethereum Smart Contracts (Using the right Gas) - Out of Gas Error

in #ethereum7 years ago

Today was a good day. I executed my first Ethereum Smart Contract. Yesterday not so much. I tried to execult my first ethereum smart contract, and I lost some cash due to an "Out of Gas" Error message. Now I am no stranger to error messages, I work in software and see many exceptions generated daily. When there is a financial loss for en error, all of a sudden you treat them a little more seriously. This is the story of what I did wrong and then how I learned a lesson on what to do and how to use Ethereum smart contracts in the future.

ETHEOSEUM.png

It cost me around $6 USD to learn this and I saw a few posts of people spending hundreds of dollars on Out of Gas errors eg (https://ethereum.stackexchange.com/questions/17515/my-transaction-failed-due-to-running-out-of-gas-can-i-recoup-this-money)

The smart contract I executed is for the EOS distribution that is using an ERC-20 token (https://steemit.com/eos/@m-i-k-e/the-eos-erc-20-contract-explained). There are many functions of the contract. If your not sure what a ERC-20 token is, just think about it as a type of smart contract that lets you own tokens designed by a third party on the ethereum blockchain. That also means that you are at the mercy of the programmer that wrote the smart contract. When I executed the claimAll() Function of the contract it cost me more then I had been willing to pay in gas. I realized that the claimAll() function just calls the Claim() function for each distribution, which at the time was in the 300's. So I ran out of gas and got the Out of Gas Error :(

out of gas.png

I did a bit of research. Found out more on how gas and the gas limit work. Basically you can set how much you want to pay for gas (unit of computation) and the total gas you are willing to spend. This way you can only screw up so much. Most wallets will help you set the price for gas but not always the limit. I set my price for gas lower and then set my gas limit higher and called the Claim() function. This way it only looks at the distribution that I sent ETH to and I made sure to cover my cost of execution. BAM! First contract execution on the ETHEREUM Blockchain!

firstTx.png

FYI: This is defiantly not investment advice!!! They are not actually using the token on the ethereum blockchain for anything other than a snapshot of who owns what when and if the network they are designing is utilized. If that sounds like total BS, it could be, so DO YOUR OWN RESEARCH. I will post more about my experience in the future so stay tuned.

Thanks for Reading
@soaljack

Sort:  

Hi SoalJack!

I have a transaction that ran out of gas when I was trying to send some ETH to poloniex.

I have 4 ETH that is stuck, its not in my wallet nor is it in poloniex.

here is a pic of the tx, can you help? https://imgur.com/a/7IovGc8

Ouch... I did not know you could lose the money you are sending as well as the tx fee. Is this common?