The Vyper Hello World !
@view @external def answer_to_everything() -> uint256: return 42
From Computers to the EVM
In the old era code or software is often run on your usual computer, a computer is in essence an information processing unit with various bridges to the outside world such as keyboards for user input, screens for output etc...
When we are in the context of Ethereum we will use the words code, program and smart contract interchangebly (they represent the same thing).
In a similar analogy Ethereum is a blockchain-based computer, the blockchain represents a historical record of every transaction that happened on-chain. Here the blockchain represents an authenticated hard-drive. The state trie represents the last known live view of the hard-drive wallets are keyboards and etherscan.io the screen.
From information processing computers rely on CPUs which in Ethereum on the otherhand to process transactions and code we rely on the EVM.
Let's start with a simple example1 transaction:
From the summary you can see that the transactions revoked access to a user's token from the 1.inch exchange.
This action simply tells the Ethereum state that the 1.inch smart contract isn't approved to spend the user's SHIB tokens.
Let's unpack this because it is kinda complex. When you go to 1.inch to execute a swap (i.e exchange tokens) you need to first approve an amount of tokens that the 1.inch contract can access and execute the swap.
This approve step essentially permits the 1.inch token to move your token once you sign the second transaction that does the actual swap.
By going to Logs tab you can see clearly which function was called in the SHIB contract in this example
approve with value 02 for balance and with spender address
The Ethereum World State
In the above drawing we used the word World State to describe the environment that encodes the last known state version, as transactions arrive bundled in blocks all the transaction in that block execute and give use a new version of the state.
Because the blockchain records all the blocks (blocks are state transitions in a more precise language) you can always replay back the full state history.
When an Ethereum node first joins the network it does just that, it will replay all past blocks until it syncs meaning has the same state as all the other nodes in the network4.
The Species inside the Ethereum World State
The Ethereum world has a very small taxonomy, there are essentially three data structures that you'll often interact with :
Etherscan summarizes all the effects a single transaction can have on the world state. ↩
The ERC20 standard describes a generic smart contract implementation for a form of pseudo-bank. ↩
This is the mainnet address of the 1.inch smart contract which is an exchange router. ↩
With snapsync nodes now can sync only a last known good copy of the state trie and replay the last k-blocks. ↩