Virtual machines

Apr 28, 2024 1:13:57 AM

A blockchain is a state machine. The term may sound technical, but the idea is simple. Let’s check this with an example. Let’s say that at one time, Alice has 5 tokens, while Bob has 2 tokens. That’s a state. Then, Alice transfers 3 tokens to Bob. Now Alice has 2 tokens, and Bob has 5. This is a new state; the initial one has been transformed into the final one.

Blockchains that implement smart contracts allow applications to manage their own state. We can think of them as new tables in a database or new columns in a spreadsheet. We can transform such states using transactions and smart contracts. The virtual machine is part of the blockchain responsible for such a state transformation.

Ethereum was the first blockchain to implement smart contracts, but nowadays, this is a feature of most blockchains. One of the main differences between them is the language used to write the contracts.

Different blockchains can share and use the same type of VM, such as Polygon or BNB Chain, that uses the EVM, Ethereum Virtual Machine. This allows smart contracts on these networks to be interoperable. Other blockchains have virtual machines unrelated to Ethereum. The Neo network, for example, uses a different VM, which is called Neo Virtual Machine.

The Neo network has the distinction of allowing several programming languages to write smart contracts. Currently, it is possible to use C#, Go, Python, or Java. Regardless of the language used, the VM is the only one that is capable of transforming the current state.

Let’s get a better understanding of the flow of a smart contract. Such flow is valid for most blockchains. First, the contract is written in high-level programming languages, such as Solidity, Python or C#. Then, using a compiler tool, the code is translated into a language that the virtual machine understands, called bytecode. Once the bytecode is generated, it must be deployed to the blockchain so anyone can interact.

Smart contracts hold code capable of transforming states but they cannot perform such transactions alone. Someone needs to submit a transaction to trigger and pay the code execution. That’s why we say that smart contracts are not that smart.

To prevent malicious users from abusing the computing power of the blockchain virtual machine, a fee is usually charged for its use, which is known as the “gas fee”. On Ethereum, the gas fee is paid with ether, the blockchain’s native token. Neo has two types of tokens, one for , called NEO, and another for paying the gas fee, called GAS. Having two tokens is another advantage of NEO, as the governance token does not decrease with its use, as in other protocols. The dual token model also allows people to participate in the network without reducing governance participation.