What is EVM?
Tags: evm, ethereum, web3
Published: 2022-02-01 15:22:03

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w47dul7zgk277x7bfb8b.png)
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](https://dev.to/getintoweb3) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l992gs7zgysdprmn8c2x.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/258j5m0466vc48fj4skv.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4o3ggv67uoimzb5uyn71.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/op0xebxn24loqh91ssuw.png)

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)](https://dev.to/getintoweb3) community for the latest updates. Also, don't forget to follow us on [Twitter](https://twitter.com/GetIntoWeb3) and join the [Discord](https://discord.gg/invite/nbbpBG3SCT) community to learn more.  

See you soon reading my next blog :)