DEV Community

Cover image for What is EVM?
Ayush Gupta for Get Into Web3

Posted on

What is EVM?

Image description
When a smart contract runs on Ethereum it's executed by the Ethereum virtual machine. In this short article, I will give you a quick intro to the Ethereum Virtual Machine (EVM), the most interesting part of Ethereum. If you are new here, I'm Ayush, a member of the Get Into Web3 community, where we make it easy for people to get started in Web3.

The Ethereum network is composed of computers called nodes. The EVM runs inside each of these Ethereum instances and the role of the EVM is to run smart contracts. The EVM is a state machine. In input, there is the state of the existing blockchain, and in output, the state is updated after a transaction has been applied.

Image description

The state of the blockchain is a mapping of accounts identified by the address to four fields-

  1. the nonce that is incremented for each transaction,
  2. the balance of ether owned by this address,
  3. the hash of the smart contract code, and
  4. the hash of the smart contract storage

Image description

The last two fields are populated only for smart contracts. For regular addresses called EOA, they are empty. The EVM can be executed in read mode and write mode.
In read mode, a user sends a request to any node of the network and the EVM of this node will process the request. In write mode, users send transactions that are mined by miners in the Ethereum network.

In each mining node, the EVM is going to process all the transactions of the new block. Each transaction is processed sequentially by the EVM in an order decided arbitrarily by each miner. For each transaction, the EVM is going to check if the transaction is valid, compute the new state of the blockchain and persist the state. For example, an address can increase its ether balance or its storage is modified. The process is repeated until all transactions are executed for this block. The miner that wins the block will propagate the new block to the network containing the hash of the new state. One important detail of the EVM is how it processes smart contracts?

Image description

Smart Contracts are basically a set of promises, specified in digital form, including protocols within which the party is performing on these promises. It's a reusable snippet of code that a developer publishes into the EVM memory. Smart contracts are often written in a programming language called Solidity. Smart contract languages like Solidity cannot be executed by the EVM directly, instead, they are compiled to a low-level machine language called opcodes. To execute specific tasks in order to efficiently store these occurrences, they are further encoded to bytecodes. Now, anyone can request the smart contract code to be executed by making a transaction request.

Image description

There comes the concept of Gas. In Ethereum, gas is essentially the fuel that allows the Ethereum network to operate. They have a market price determined by the demand for resources on the network. The amount of gas you need depends on how complex of a smart contract function you are trying to execute and how fast you want to execute it. The gas fee keeps the Ethereum network secure, preventing actors from scamming the network.

The potential use case of the EVM and decentralized apps are huge and developers are working every day to make the entire ecosystem better.

That's it for this quick intro to the Ethereum virtual machine (EVM). Going forward, if you want to know more about the technologies associated with Web3, don’t forget to follow and be a part of the Get Into Web3 (GIW3) community for the latest updates. Also, don't forget to follow us on Twitter and join the Discord community to learn more.

See you soon reading my next blog :)

Discussion (5)

Collapse
jonrandy profile image
Jon Randy

An extremely slow, limited, over-complicated, polluting computer... that you have to pay to use

Collapse
darkwiiplayer profile image
DarkWiiPlayer

Technically, "pay to use" applies to every computer unless you own an army of hamsters.

Collapse
jonrandy profile image
Jon Randy • Edited on

Yeah, but it's not like:

Me: Computer, calculate the result of 1+1
Computer: Sure, that'll be 76 gwei, please. I'll have it done in about an hour

Thread Thread
darkwiiplayer profile image
DarkWiiPlayer

Yep, I was just pointing out the technicality; EVM is much more expensive, of course

Collapse
kcubeterm profile image
Krishna Kanhaiya

What is EVM ?
Electronic Voting Machine