Gas from the Ether: Crypto-fuel for the Consensus Network

Image source:

In Part 1 of this series, we discussed smart contracts are and briefly went over the concept of gas cost. In this article, we’re going over what this means for miners, the ways it impacts Dapp developers, and how a pizza restaurant can help explain transaction cost while differentiating ETH from tokens.

To recap what we learned about gas cost:

  1. One gas is the cost of a unit of work in Ethereum.
  2. Nodes set gas prices on the network and if you request a gas price that’s too low, no nodes will pick up your work and perform it.
  3. Gas is paid when you execute a contract.
  4. Only the gas used is consumed.
  5. You set a spending limit on how much gas the transaction can use.
  6. If your executed smart contract goes over budget, you lose your gas, and the transaction is marked incomplete.
  7. If your executed smart contract goes over the Block Gas Limit, your smart contract is also rejected, regardless of your budget.
  8. If all goes well, then the node is paid, and you get your results. Everyone is happy!

Let’s take a look at how this is used in reality.

Gas is the node’s incentive for executing smart contracts.

Let’s talk mining…

You’re a miner and you’ve got these here low-end servers. They’re just sitting on your racks, 40% utilized. They’re never going to compete with what’s out there, but they are still being utilized by six companies. You could decommission them, but they’re really operating fine the way they are. How can you get the most out of the other 60%? You could spend time marketing these low-end servers but eh, why?

Then your buddy comes along. He’s just gotten into cryptocurrencies and made a bit of money off of Bitcoin. He took his old servers, hooked them up with GPUs, and started grinding away at Bitcoin. He makes a bit more than the cost of running the machines, mostly due to location, but some profit is better than no profit, right?

So you look into it. You’d have to foot the bill to suit up all of these older machines with GPUs trying to grind out new solutions for the blockchain. It’s pretty hit-or-miss, and you’re hearing of new ASICs which makes a lot of the GPU stuff obsolete. Maybe Bitcoin isn’t the way to go.

Your buddy comes back to you. “Hey have you heard of Ethereum yet?” You hadn’t, so you do a bit of digging. Apparently you can run an Ethereum node and execute smart contracts on behalf of other Ethereum developers and rake in transaction fees that way. The nodes don’t require a GPU and you get to take in the transaction fees associated with executing the smart contracts on the network. While the current value doesn’t generate to a profit, at the rate Ethereum is climbing in value, you see the cryptocurrency as an investment of value. Besides, you weren’t using these resources anyway. So you set up some nodes and are now executing smart contract byte code on behalf of Dapp developers. You’re paid in gas.

Better watch how much gas you’re using!

Let’s talk developing…

You’re a developer. You’ve got this idea for an application. You’re in the middle of developing it, and your buddy comes along and says, “Hey, this could be a really cool Dapp!” Since you hadn’t heard of Ethereum or “Decentralized Applications,” you listen to him speak about blockchain and Ethereum and smart contracts. It all starts to click, and you decide your application would be a fantastic Dapp. So you get to work, and when you’re testing with dummy data, you realize that it would cost your customers $7.35 worth of ETH just to run the transactions that your Dapp required once.

“This is nuts!” you exclaim, blaming the network for its unreasonable fees. “How can anyone build a system this INSANE!”

“Hold on,” your buddy says. “Did you optimize your contract code?

You frown. You hadn’t thought of that. You remember what you had read in your tutorials: gas is a function of cost per operation on the EVM. You have not one, but several brute-force algorithms in your smart contract. On top of that, you’re executing them in places you don’t have to and could be caching results instead. Your face turns a bit red and you go back to work. In the EVM, work is money. Make sure it works smarter, not harder.

Ethereum is the exchange network, but the tokens hold their own value.

Let’s talk currency…

You’re a new blockchain company. You found a way to launch widgets in the blockchain. You call them Foglets, and these Foglets are purchased with and utilize your ERC20 token, the FoggyCoin. Rather than back your company using traditional venture capital methods, you publish a whitepaper and issue your tokens. You offer a pre-sale wallet to those who want some tokens at a low early price. Your pre-sale was a huge success! You’re doing great and you’re just about ready to release the FoggyCoin into the wild.

Then the price on ETH drops…And, the confusion starts.

Your users are in an uproar! “I bought these tokens, they’re backed by ETH! If ETH prices are down, the FoggyCoin is worthless! Uninformed buyer’s remorse! Rabble rabble rabble!” It’s loud, and your inbox has become very busy.

“Calm down guys, our token is issued in ETH, but the FoggyCoin’s value is in itself.”

“No! ETH is like gold! It backs the token’s value!” they shout, not listening to what you’re saying.

“No, my friends, this is simply not the case. You see, the token is issued using the Ethereum network platform as a smart contract. The value of the FoggyCoin is in the value of our product, Foglets, not in the value of Ethereum. If anything, this just means your transaction fees will go down relative to your chosen fiat if gas price remains the same.

“This makes no sense! If I buy them using ETH, a FoggyCoin is ETH! This token is ETH!” other users begin to cross-shout, and it becomes a mess.

You sigh and begin to frame it in a way they can all understand:

“If you buy tokens in Chuck E. Cheese, and while in there playing Skee Ball, the dollar drops in value by half, does this mean your tokens are now worth half as much as they once were and you can play half as many games? No, because the token’s value is independent of the value of the currency you bought it with. It has value in the environment of Chuck E. Cheese. Outside of Chuck E. Cheese, it’s not very useful. Our token is not dependent on the value of ETH. It’s dependent on the value of itself in the context of the exchange environment we’ve established. ETH is just what you use to buy FoggyCoins, and if you don’t feel it’s as valuable as at the time in which you bought it, that’s fine. Unlike Chuck E. Cheese, you can always sell our tokens back to others. When you do, you pay transaction fees in gas, which is ETH, not FoggyCoins.”

Then the price of ETH jumped 1.5x and everyone forgot the discussion. Their transaction fees now cost more but they think the value of their tokens is up so they’re happy. You sigh, relieved, but knowing this will happen every single time the price of ETH drops, you decide it’s time to write a script to handle the PR of these situations before you get back to writing more Foglets.

To summarize, when considering gas costs, you really should know the following:

  1. Gas is paid to the nodes running the smart contracts for the work they complete, whether or not your task finishes.
  2. Suboptimal code can cost the user of your Dapps a pretty penny.
  3. Tokens are traded using gas, so your token transaction fees are dependent on gas cost, even though your tokens, themselves, are not.

I hope this helps someone!

Like what you read? Give Collin Cusce a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.