HowTo VeChain Blockchain — Part 7.1

What is GAS and how to calculate it — Part 1

MiRei
4 min readNov 22, 2020

(Links to all parts at the bottom)

This part will be about gas and VTHO. I did struggle some time with the concept of gas so I will try to explain it in understandable language as well as show technical details for it.

What is gas?

Gas is an inheritance from ethereum and represents the value of a transaction in a technical sense. To be more accurate, gas is to quantify the consumption of storage and computing on the entire blockchain network. It’s about how valueable the transaction is to the blockchain, not to a real-life person.

There are two parts in gas calculation:

  • Data stored on the blockchain (can be calculated off-chain)
  • Data computed by the blockchain (must be calculated on-chain)

Imagine this:

I want to build a house. Therefore I need bricks. So a truck will load (store) bricks and deliver them to me. The more bricks stored on the truck, the more expensive it will be. So now I have a hughe pile of bricks. But this is not a house. I need someone who will build a house from those bricks and so another machine will actually assemble the bricks (compute data). That’s basically how gas on vechain and ethereum works. The bigger the amount of data stored and the more complex the smart contract the higher the amount of gas needed to process this transaction. And you always have to pay upfront!

What is the gaslimit?

The gaslimit limits the amount of gas that can be used (this means “data stored” and “data computed”) in one block. At the time of writing this it’s 12.500.000 in ethereum and about 35.000.000 in Vechain. But VeChains gaslimit is dynamic and already reached 198.901.910 gas in block 6.757.225. It will increase and decrease if needed, much like the difficulty in Bitcoin.

The idea behind this limit is, to prevent blocks with huge gas peaks, followed by a lot of empty blocks. It is to prevent the blockchain from overload. The Authority Nodes in Vechain have to build a new block every 10 seconds. The bigger the block, the bigger the computing time needed to build it. If an Authority Nodes takes too much time to produce a block (close to or exceed the 10s block interval), the block may conflict with another block in the next time slot, which would cause a minor fork. So the gaslimit is a mechanic to cap the amount of gas in each block and distribute transactions into more blocks.

How is gas correlated to vetho?

As decribed above, gas is the technical base for all calculations inside the blockchain but at some point you need to pay. So gas is linked to a token. In ethereum gas is directly linked to ETH itself. In VeChain it’s linked to VTHO, the second token in the VeChain ecosystem.

Since the mainnet start in 2018 the link between gas and VTHO is:

  • 1000 gas = 1 VTHO

This correlation can be changed by the VeChain Steering Committee voting (if really really needed). This is something that will not happend every other month or due to short term fluctuations in usage/price.

Now lets pick a random transaction.

Transaction on VeChain mainnet with gas cost of 37.000

This transaction has consumed 37.000 gas on the vechain blockchain. So the transaction will cost 37 VTHO. But there is also another value behind the actual cost of the transaction with 55.000. This is a value set by the sender of the transaction to determin the maximum gas that this transaction can consume. If it uses more, it will revert. This is the most common reason for reverted transactions.

Do the math!

The VeChain team has a greate article about how to calculate the storing gas cost. It’s very mathematical but once it clicked, it’s not that difficult.

Transaction calculation:

  • Every transaction has a base cost of 5.000 gas
  • A contract creation clause adds 48.000 gas
  • A normal clause adds 16.000
  • Every “00” in the data filed adds 4 gas
  • Everything other than “00” adds 68 gas

So in the transaction shown above there are two (vet) clauses with no extra data:

5.000 + 16.000 + 16.000 = 37.000

But thats just for “non-contract” interactions. As soon as you put data into a contract the VeChain software needs to calculate the computing cost based on data transmitted to it. This will be covered in the next part!

HowTo VeChain Blockchain — Part 1: Create a wallet

HowTo VeChain Blockchain — Part 2: What’s a transaction made of?

HowTo VeChain Blockchain — Part 3: Build a VET transaction

HowTo VeChain Blockchain — Part 4: Creating a multi-clause transaction

HowTo VeChain Blockchain — Part 5: Python-powered VET transfers

HowTo VeChain Blockchain — Part 6: Putting data on the Blockchain

HowTo VeChain Blockchain — Part 7.1: What is GAS and how to calculate it

--

--