WHITE PAPER – June 2021

In collaboration with the Wharton Blockchain and Digital Asset Project

Foreword

Decentralized finance (DeFi) is an emerging and rapidly evolving area in the blockchain environment. Although examples of DeFi have existed for several years, there was a sudden upsurge of activity in 2020. In one year, the value of digital assets1 locked in DeFi smart contracts grew by a factor of 18, from $670 million to $13 billion; the number of associated user wallets grew by a factor of 11, from 100,000 to 1.2 million; and the number of DeFirelated applications grew from 8 to more than 200.2 This growth in turn has stimulated interest from both the private and public sectors.
DeFi aims to reconstruct and reimagine financial services on the foundations of distributed ledger technology, digital assets and smart contracts. As such, DeFi is a noteworthy sector of financial technology (fintech) activity.

However, serious questions remain:

– What, if any, are the distinctive aspects of DeFi? What distinguishes a DeFi service from a similar service based on traditional finance?

– What are the opportunities and potential benefits of DeFi? To whom will these benefits accrue – and who might be excluded or left behind?

– What are the risks – individual, organizational and systemic – of using DeFi? How do these risks apply to clients, markets, counterparties and beyond?

– Can DeFi become a significant alternative to traditional financial services? If so, will there be points of integration? If not, what if anything will DeFi represent in the market?

– What novel legal and policy questions does DeFi raise? How should policy-makers approach DeFi? What options exist for addressing these questions?

Notably, the DeFi space is relatively nascent and rapidly evolving, so the full scope of risks and potential for innovation remain to be seen – and there are unique challenges in regulating and creating policies for such a new and changing area.
This report does not recommend any one single approach; instead, it is designed as a set of tools that can be applied in light of the legal contexts and policy positions of each jurisdiction, which may vary.
In the appendices we offer a series of worksheets and other tools to assist with the evaluation of DeFi activities. A companion piece, DeFi Beyond the Hype, provides additional detail about the major DeFi service categories.
Our hope is that this resource will enable regulators and policy-makers to develop thoughtful approaches to DeFi, while helping industry participants understand and appreciate public-sector concerns.
It is the result of an international collaboration among academics, legal practitioners, DeFi entrepreneurs, technologists and regulatory experts. It provides a solid foundation for understanding the major factors that should drive policy-making decisions.

Download the full report:

http://www3.weforum.org/docs/WEF_DeFi_Policy_Maker_Toolkit_2021.pdf

The Emerging World of Decentralized Finance

Produced by the Wharton Blockchain and Digital Asset Project, in collaboration with the World Economic Forum

Introduction

Decentralized Finance (DeFi) is a developing area at the intersection of blockchain, digital assets, and financial services. DeFi protocols seek to disintermediate finance through both familiar and new service arrangements. The market experienced explosive growth beginning in 2020. According to tracking service DeFi Pulse, the value of digital assets1 locked into DeFi services grew from less than $1 billion in 2019 to over $15 billion at the end of 2020, and over $80 billion in May 2021.2 Yet DeFi is still early in its maturation.

The goal of this report is to demystify DeFi. It describes the basic attributes of DeFi services, the structure of the DeFi ecosystem, and emerging developments. A forthcoming Decentralized Finance Policy-Maker Toolkit will offer guidance on risks and policy approaches for governments navigating this new space.
DeFi is a general term covering a variety of activities and business relationships. We identify six major DeFi service categories—stablecoins, exchanges, credit, derivatives, insurance, and asset management—as well as auxiliary services such as wallets and oracles. While traditional finance relies on intermediaries to manage and process financial services, DeFi operates in a decentralized environment—public, permissionless blockchains.

Services are generally encoded in open-source software protocols and smart contracts. Like blockchain technology more generally, DeFi has an enthusiastic base of evangelists, who promote its potential for efficiency, transparency, innovation, and financial inclusion. It also has its critics, risks, and unknowns. There have already been significant examples of fraud, attacks, governance controversies, and other failures in the DeFi world. At this early stage, it is essential for industry and governments alike to develop a well-informed and nuanced understanding of the opportunities, risks, and challenges.

What is DeFi?

THE FUNDAMENTALS

DeFi is a general term for decentralized applications (Dapps) providing financial services on a blockchain settlement layer, including payments, lending, trading, investments, insurance, and asset management. DeFi services typically operate without centralized intermediaries or institutions, and use open protocols that allow services to be programmatically combined in flexible ways.

Historically, intermediaries have played essential roles within financial markets, serving as agents and brokers of trust, liquidity, settlement, and security. The range and value of intermediaries has grown over time to meet the needs of an increasingly complex financial system. Since the 2008 Global Financial Crisis, there has been increased attention on inefficiencies, structural inequalities, and hidden risks of the intermediated financial system. More recently, controversies such as the GameStop short squeeze, in which retail investors were blocked from trading during a period of volatility, cast a spotlight on other shortcomings of legacy financial infrastructure:

slow settlement cycles, inefficient price discovery, liquidity challenges, and the lack of assurance around underlying assets.

DeFi aims to address some of these challenges—though many still apply to the DeFi ecosystem in its current state.

DeFi leverages blockchain technology to facilitate alternatives to traditional service providers and market structures. It offers the potential for innovation and creation of new services for improving efficiency of financial markets—building upon work being done in financial technology (fintech) and blockchain technology more broadly. Whether it achieves this promise remains to be seen…

Download the full report:

https://wifpr.wharton.upenn.edu/wp-content/uploads/2021/05/DeFi-Beyond-the-Hype.pdf

Placeholder
Source: https://www.placeholder.vc/blog/2021/3/10/systemic-risk-mitigation-in-defi
March 11, 2021

Introduction

Speculation and risk-taking are essential features of all monetary economies and both are closely tied to the financial sector. History has shown that without appropriate rules, safeguards, and behavioral norms, financial markets become more prone to fraud, pro-cyclical excess, and crises. Occasionally, these crises take systemic proportions, threatening the stability of the economic system as a whole. In a worst case scenario, a financial meltdown can lead to an economic depression, extreme social divisions, or even violent political conflict.

Weiterlesen


Zusammenfassung

Wenn Sie begonnen haben, Ihren Zeh in die Welt des Ethereum einzutauchen, haben Sie wahrscheinlich Etherscan gesehen oder wurden dorthin umgeleitet. Etherscan ist ein Block-Explorer, der es Benutzern ermöglicht, Informationen über Transaktionen anzuzeigen, die an die Blockchain übermittelt wurden, den Vertragscode zu überprüfen und Netzwerkdaten zu visualisieren. Dieser Leitfaden konzentriert sich auf die Erläuterung der Informationen, die für verschiedene Arten von Transaktionen auf Etherscan angezeigt werden.


Komponenten einer Ethereum-Transaktion auf Etherscan

  • Transaktions-Hash: Ein eindeutiger Identifier, der verwendet werden kann, um eine bestimmte Transaktion zu lokalisieren.
  • Status: Der aktuelle Status einer Transaktion (erfolgreich, fehlgeschlagen oder schwebend).
  • Block: Die Blocknummer, in den die Transaktion aufgenommen wurde.
  • Zeitstempel: Die Zeit, zu der der Block gemined wurde, in UTC.
  • Von: Das Konto, von dem die Transaktion ursprünglich gesendet wurde.
  • An: Das Konto, an das die Transaktion adressiert ist.
  • Wert: Der Betrag von Ether, der in der Transaktion enthalten ist.
  • Transaktionsgebühr: Der an den Miner für die Abwicklung der Transaktion gezahlte Ether-Betrag, der durch Multiplikation der verbrauchten Gasmenge mit dem Gaspreis berechnet wird.
  • Gaslimit: Die Obergrenze, wie viel Rechenarbeit und Speicherplatz der Sender bereit ist, für die Transaktion aufzuwenden.
  • Von der Transaktion verbrauchtes Gas: Die Menge an Rechen- und Speicherarbeit, die für die Transaktion verwendet wird.
  • Gaspreis: Die Menge an Ether pro Gaseinheit, die der Nutzer bereit ist, für die Transaktion zu zahlen, üblicherweise in einer Untereinheit von Ether, die als Gwei bezeichnet wird. 1 Gwei = 1×10^-9 Ether.
  • Nonce: Die Anzahl der Transaktionen, die vom Konto weggeschickt werden. Die Zahl wird mit 0 initialisiert und für jede gesendete Transaktion um 1 erhöht.
  • Eingabedaten: Informationen, die an einen intelligenten Vertrag übergeben werden, wenn eine Transaktion an seine Adresse gesendet wird. Wenn die Transaktion jedoch einen Vertrag erstellt, wird der Bytecode des Vertrags in das Eingabedatenfeld gesetzt.

Ich empfehle Ihnen, diesen Artikel zu lesen, wenn Sie mit der Verwendung von Gas in Ethereum nicht sehr vertraut sind. Weiterlesen

Lending is the natural next step for any new nascent financial market. The house of Rothschild got its start by collecting and exchanging coins (moneychanging). Once they had enough value under their custody, the natural step was to put it to work (moneylending). Then they expanded by doing the same for rulers locally and then, doing the same across Europe.

Overview

This is a simple working example of a flash arbitrage smart contract, whereby within a single transaction it:

  1. Instantly flash borrows a certain asset (ETH in this example) from Aave lending pools with zero collateral
  2. Calls UniswapV2 Router02 to wrap the flash liquidity of ETH into WETH and exchange it for DAI tokens
  3. Checks the exchange rate of DAI back into ETH on Sushiswap V1
  4. Calls SushiswapV1 Router02 to swap the DAI back into WETH and then ETH
  5. There’s also an independent function to withdraw all ETH and ERC20 tokens at the contract owner’s discretion

Before you start playing with this I highly recommend to have a read of the Aave Flash Loan mechanism and get an indepth conceptual understanding, as it’s equally important as understanding the code.

Since Sushiswap is a fork of UniswapV2, I also suggest familiarising yourself with the Uniswap V2 guide on trading via smart contracts, particularly if you plan on adding more swaps to your arbitrage strategy.

Deployment

The contract can be plonked directly onto Remix, using solidity compiler 0.6.12, and Metamask using Injected Web3.

On deployment, set the following parameters:

  • _AaveLendingPool: the LendingPoolAddressesProvider address corresponding to the deployment environment. see Deployed Contract Instances.
  • _UniswapV2Router: the Router02 address for UniswapV2 see here.
  • _SushiswapV1Router: the Router02 address for SushiswapV1. There isn’t an official testnet router02 so for demo purposes you can just use the uniswapV2 address when playing on the testnet since their codebase is identical (for now – which may not be the case in the future). Alternatively see Sushiswap repo for the mainnet router02 address to test in prod or deploy your own version of Router02 onto testnet.
  • Click ‚transact‘ and approve the Metamask pop up.
  • Once the flash arb contract is deployed, send some ETH or ERC20 token to this contract depending on what asset you’re planning to flash borrow from Aave in case you need extra funds to cover the flash fee.

Execution

On execution, set the following parameters:

  • _flashAsset: address of the asset you want to flash loan. e.g. ETH is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE. If you want to flash anything else see Reserved Assets but you will need to adjust the executeArbitrage() function accordingly.
  • _flashAmount: how much of _flashAsset you want to borrow, demoniated in wei (e.g. 1000000000000000000 for 1 ether).
  • _daiTokenAddress: for this demo we’re swapping with the DAI token, so lookup the reserved address of the DAI token. See Reserved Assets.
  • _amountToTrade: how much of the newly acquired _flashAsset you’d like to use as part of this arbitrage.
  • _tokensOut: how much of the ERC20 tokens from the first swap would you like to swap back to complete the arb. Denominated in actual tokens, i.e. 1 = 1 DAI token.
  • Click ‚transact‘ and approve in Metamask.

Result

If all goes well, a successful execution of this contract looks like this (Ropsten testnet).

Tips for further customization

  • This contract would typically be executed by a NodeJS bot (not part of this demo) via a web3.eth.Contract() call, referencing the deployed address of this contract and its corresponding ABI. You would usually get the bot to interact with price aggregators such as 1inch to assess arb opportunities and execute this contract if the right opportunity is found.
  • To have any chance of getting in front of other arb bots on significant arb opportunities the NodeJS bot needs to be hosted on your own fast Ethereum node. You will most likely come off second best going through the Infura API to interact with the Ethereum blockchain.
  • Some people like to get an unfair advantage by building Transaction-Ordering Dependence (front running) capabilities into the NodeJS component, typically using web3.eth.subscribe(‚pendingTransactions‘..) to monitor for newly submitted arb TXs. However this smart contract would then need to be significantly more complex and flexible enough to cater for a wide range of arbitrage permutations across multiple protocols.
  • User specified parameters (as opposed to hardcoded variables) should be passed via the flashloan() function in the first instance. You can subsequently set these parameters to contract variables with higher visibility across the contract.
  • There are no direct ETH pairs in UniswapV2 therefore the need for a WETH wrapper. Since Sushiswap is forked from UniswapV2 you’ll need to wrap in WETH as well.

If you found this useful and would like to send me some gas money:

0xef03254aBC88C81Cb822b5E4DCDf22D55645bCe6

Thanks, @fifikobayashi

Source: https://github.com/fifikobayashi/Flash-Arb-Trader

  • The European Commission has today officially proposed a regulatory framework for crypto-assets and stablecoins after a leaked draft proposal went viral last week.
  • The official proposal recommends a “bespoke” regime for crypto-assets and stablecoins.
The European Commission has today officially proposed a regulatory framework for crypto-assets and stablecoins after a leaked draft proposal went viral last week.

The 168-page official draft proposal (provisional), published Thursday, highlights the need for a „sound“ legal framework, clearly defining the regulatory treatment of all crypto-assets that are not covered by existing EU financial services legislation.

Crypto assets, especially stablecoins, have the potential to become widely accepted, said the commission. Hence, they would be subject to „more stringent requirements“ regarding capital, investor rights, and supervision. The proposal is in line with the leaked version from last week.

The commission has today proposed a „bespoke“ regime for crypto-assets and stablecoins. „The bespoke regime for crypto-assets will ensure a high level of consumer and investor protection and market integrity, by regulating the main activities related to crypto-assets,“ said the commission. The main activities include such as crypto exchange and wallet services.

„By imposing requirements (such as governance, operational requirements) on the main crypto-asset service providers and issuers operating in the EU, the proposal is likely to reduce the amounts of fraud and theft of crypto-assets,“ said the commission, adding:

„The bespoke regime will introduce specific requirements on e-money tokens, significant e-money tokens, asset-referenced tokens and significant asset-referenced tokens in order to address the potential risks to financial stability and monetary policy transmission these can present. Finally, it will address market fragmentation issues arising from the different national approaches across the EU.“

The commission has today also proposed a regulatory sandbox to allow companies to test blockchain technology in trade and settlement processes.

The proposals are part of the commission’s newly adopted Digital Finance Package. The package will „boost Europe’s competitiveness and innovation in the financial sector, paving the way for Europe to become a global standard-setter,“ said the commission. „It will give consumers more choice and opportunities in financial services and modern payments, while at the same time ensuring consumer protection and financial stability.“

Source: theblockcrypto.com

PDF-Document – REGULATION OF THE EUROPEAN PARLIAMENT AND OF THE COUNCIL

What Are Cryptocurrencies?

A potential new form of money offers benefits while posing risks

Antoine Bouveret and Vikram Haksar

Back to Basics

Hundreds of them have sprouted, with fanciful names like Primecoin, Dash, and Verge. They have developed cult-like followings among the tech-savvy. Their values fluctuate wildly. Some people say these mysterious bits of computer code will someday replace money as we know it. What exactly are these cryptocurrencies, and what makes people think they are worth anything at all? To answer these questions, let’s first look at how money evolved.

Uses of money

Money serves as a store of value, a means of exchange for goods and services, and a unit of account that measures value. Before money, human societies exchanged goods and services directly—a bushel of grain for a pig, say. This was not very efficient. As societies grew more complex, commodity monies were developed—from seashells to copper, silver, and gold. Some states introduced fiat money—which has no intrinsic value other than the promise to pay—such as paper money in eighth century China under the Tang dynasty.

Most early forms of fiat money were neither very stable nor widely accepted, as people did not believe the issuer would honor its commitment to redeem the money. Governments were tempted to print more money to buy goods or raise wages, which fueled inflation (think of people moving cash around in wheelbarrows in post–World War I Germany). Modern central banks seek to maintain price stability by regulating the supply of money on behalf of governments.

Bookkeeping and ledgers

An increasingly extensive and complex financial system gave rise to the need for trusted intermediaries and credible accounting systems. The development of double-entry bookkeeping in Renaissance Italy was a major innovation that strengthened the role of large private banks. In modern times, central banks emerged at the apex of payment systems. With computerized bank ledgers, the coordinating role of central banks increased.

How do such ledgers work? Financial institutions adjust the positions of their account holders in their internal ledgers, while the central bank validates transactions among financial institutions in a central ledger. For example, Mehrnaz uses money from her account in bank A to buy goods from Mary, who has an account in bank B. Bank A debits the money from Mehrnaz’s account. The central bank moves money from bank A to bank B and records the transaction in its central ledger. Bank B then adds the money to Mary’s account. As you can see, the system is based on trust in the central bank and in its ability to safeguard the integrity of the central ledger and ensure that the same money is not spent twice.

With many cryptocurrencies, on the other hand, there is no need for a trusted central agent. Instead, they rely on distributed ledger technology, such as blockchain, to construct a ledger (effectively a database) that is maintained across a network. To ensure that the same cryptocurrency is not spent twice, each member of the network verifies and validates transactions using technologies derived from computing and cryptography. Once a decentralized consensus is achieved among members of the network, the transaction is added to the ledger, which is validated. The ledger provides a complete history of the transactions associated with a particular cryptocurrency that is permanent and cannot be manipulated by a single entity. This ability to achieve consensus on the validity of transactions between accounts in a distributed network is a foundational technological shift.

Network members who verify and validate transactions are usually rewarded with newly minted cryptocurrency. Many cryptocurrencies are also pseudo-anonymous: holders of the currency have two keys. One is public, such as an account number; another, private key is required to complete a transaction. So, to continue the previous example, Mehrnaz wants to buy goods from Mary using a cryptocurrency. To do so, she initiates a transaction with her private key. Mehrnaz is identified in the network by her public key, ABC, and Mary is identified by hers, XYZ. Network members verify that ABC has the money she wants to transfer to XYZ by solving a cryptography puzzle. Once the puzzle is solved, the transaction is validated, a new block representing the transaction is added to the blockchain, and the money is transferred from ABC’s wallet to XYZ’s.

Benefits, risks

Now that we understand the technology, let’s return to the genesis of cryptocurrencies. The first one, Bitcoin, was introduced in 2009 by a programmer (or group of programmers) using the pseudonym Satoshi Nakamoto. As of April 2018, there were more than 1,500 cryptocurrencies, according to coinmarketcap.com; along with Bitcoin, Ether and Ripple are the most widely used.

Despite the hype, cryptocurrencies still don’t fulfill the basic functions of money as a store of value, means of exchange, and unit of account. Because their value is highly volatile, they have little use so far as a unit of account or a store of value. Limited acceptance for payment restricts their use as a medium of exchange. Unlike with fiat money, the cost of producing many cryptocurrencies is high, reflecting the large amount of energy needed to power the computers that solve the cryptographic puzzles. Finally, decentralized issuance implies that there is no entity backing the asset, so acceptance is based entirely on users’ trust.

Cryptocurrencies and their underlying technologies offer benefits but also carry risks. Distributed ledger technology could reduce the cost of international transfers, including remittances, and foster financial inclusion. Some payment services now make overseas transfers in a matter of hours, not days. The technology can provide benefits beyond the financial system. For example, it can be used to securely store important records, such as medical histories and land deeds. On the other hand, the pseudo-
anonymity of many cryptocurrencies makes them vulnerable to use in money laundering and terrorism financing, if no intermediary checks the integrity of transactions or the identity of the people making them. Cryptocurrencies could also eventually present challenges for central banks were they to affect control over the money supply and therefore the conduct of monetary policy.

Source: imf.org

BaFin nimmt Interessenbekundungen entgegen

Durch das Gesetz zur Umsetzung der Änderungsrichtlinie zur vierten EU-Geldwäscherichtlinie wird das Kryptoverwahrgeschäft als neue Finanzdienstleistung in das KWG aufgenommen. Das vom Gesetzgeber bereits beschlossene Gesetz tritt am 01.01.2020 in Kraft. Unternehmen, die dieses Geschäft dann erbringen wollen, benötigen eine Erlaubnis der BaFin. Die BaFin bittet interessierte Unternehmen bereits jetzt um eine formlose und unverbindliche Interessenbekundung.

Anträge für die Erlaubnis zur Erbringung des Kryptoverwahrgeschäftes kann die BaFin erst entgegennehmen, wenn das Gesetz in Kraft ist. Gleichwohl bittet die BaFin bereits jetzt um Interessenbekundungen von Unternehmen, die bereits das Kryptoverwahrgeschäft erbringen oder die Erbringung beabsichtigen.

Diese Interessenbekundungen sollten neben dem Namen des Unternehmens und der Ansprechpartner auch ein kurze Beschreibung des Geschäftsmodells von maximal einer Seite enthalten. Weitere Informationen sind vorläufig nicht einzureichen.

Die Interessenbekundungen sind vorzugsweise per E-Mail oder postalisch an folgende Adresse zu senden:

Bundesanstalt für Finanzdienstleistungsaufsicht
Gruppe IT-Aufsicht – Kryptoverwahrgeschäft
Graurheindorferstraße 108
53117 Bonn

Bitte beachten Sie die Hinweise zur gesicherten Kommunikation per E-Mail mit der BaFin.

Die BaFin möchte mit diesem Verfahren einen reibungslosen Übergang auf die neue Rechtslage ermöglichen und frühzeitig einen Überblick über den Markt erhalten. Die Unternehmen werden auf ihre Interessenbekundung keine unmittelbare Eingangsbestätigung oder Einschätzung zu den eingereichten Angaben erhalten.

Es ist beabsichtigt den Unternehmen, die ihr Interesse bekundet haben, nähere Informationen und Hinweise mitzugeben, sobald die BaFin ihre Verwaltungspraxis zu der Zulassung und der laufenden Aufsicht für die neue Finanzdienstleistung konkretisiert hat. Grundsätzlich richtet sich das Erlaubnisverfahren für das Kryptoverwahrgeschäft nach § 32 Abs. 1 KWG, weshalb das bereits bestehendeMerkblatt der Deutschen Bundesbank über die Erteilung einer Erlaubnis zum Erbringen von Finanzdienstleistungen vom 06.07.2018 berücksichtigt werden kann. Die Unternehmen sind daher eingeladen ihre Interessenbekundung mit aus ihrer Sicht noch offenen Grundsatzfragen zu verbinden. Die Interessenbekundung ist formlos und unverbindlich. Sie ist zudem freiwillig und hat keine Auswirkungen auf ein zukünftiges Erlaubnisverfahren.

Die Interessenbekundung ersetzt nicht die förmliche Anzeige nach § 64y KWG n.F. Das Gesetz sieht in § 64y KWG n.F. verschiedene Übergangsbestimmungen für bereits tätige Unternehmen vor. Für ein Unternehmen, das auf Grund des neuen Erlaubnistatbestands Kryptoverwahrgeschäft ab dem 01.01.2020 zum Finanzdienstleistungsinstitut wird, gilt die Erlaubnis für den Betrieb dieses Geschäfts als zu diesem Zeitpunkt vorläufig erteilt, wenn es bis zum 30. November 2020 einen vollständigen Erlaubnisantrag stellt und wenn es die Absicht, einen Erlaubnisantrag zu stellen, bis zum 31. März 2020 der Bundesanstalt schriftlich anzeigt. Die gesetzliche Vorgabe in § 64y KWG n.F. setzt nach ihrem Wortlaut eine schriftliche Absichtsanzeige voraus.

Source: https://www.bafin.de/DE/Aufsicht/BankenFinanzdienstleister/Zulassung/Kryptoverwahrgeschaeft/kryptoverwahrgeschaeft_artikel.html

Hier ein etwas ausführlicher Artikel zu diesem Thema: New law makes Germany “crypto heaven”

An Ultimate, In-depth Explanation of How EVM Works.

This post is a continuation of my Getting Deep Into Series started in an effort to provide a deeper understanding of the internal workings and other cool stuff about Ethereum and blockchain in general which you will not find easily on the web. Here are the previous parts of the Series in case you missed them:

Getting Deep Into Geth: Why Syncing Ethereum Node Is Slow
Downloading the blocks is just a small part. There is a lot of stuff going on…
Getting Deep Into Ethereum: How Data Is Stored In Ethereum?
In this post, we will see how states and transactions are stored in Ethereum and how it is different from Bitcoin.

In this part, we are going to explore explain and describe in detail the core behavior of the EVM. We will see how contracts are created, how message calls work, and take a look at everything related to data management, such as storagememorycalldata, and the stack.

To better understand this article, you should be familiar with the basics of the Ethereum. If you are not, I highly recommend reading these posts first.

8 Resources to Get Started With Ethereum
The ultimate guide for understanding & Starting with Ethereum.

Throughout this post, we will illustrate some examples and demonstrations using sample contracts you can find in this repository. Please clone it, run npm install, and check it out before beginning.

Enjoy, and please do not hesitate to reach out with questions, suggestions or feedback.

EVM: 10,000 ft Perspective

Before diving into understanding how EVM works and seeing it working via code examples, let’s see where EVM fits in the Ethereum and what are its components. Don’t get scared by these diagrams because as soon as you are done reading this article you will be able to make a lot of sense out of these diagrams.

The below diagram shows where EVM fits into Ethereum.

The below diagram shows the basic Architecture of EVM.

This below diagram shows how different parts of EVM interact with each other to make Ethereum do its magic.

We have seen what EVM looks like. Now it’s time to start understanding how these parts play a significant role in the way Ethereum works.

Ethereum Contracts

Basics

Smart contracts are just computer programs, and we can say that Ethereum contracts are smart contracts that run on the Ethereum Virtual Machine. The EVM is the sandboxed runtime and a completely isolated environment for smart contracts in Ethereum. This means that every smart contract running inside the EVM has no access to the network, file system, or other processes running on the computer hosting the VM.

As we already know, there are two kinds of accounts: contracts and external accounts. Every account is identified by an address, and all accounts share the same address space. The EVM handles addresses of 160-bit length.

Every account consists of a balance, a noncebytecode, and stored data (storage). However, there are some differences between these two kinds of accounts. For instance, the code and storage of external accounts are empty, while contract accounts store their bytecode and the Merkle root hash of the entire state tree. Moreover, while external addresses have a corresponding private key, contract accounts don’t. The actions of contract accounts are controlled by the code they host in addition to the regular cryptographic signing of every Ethereum transaction.

Creation

The creation of a contract is simply a transaction in which the receiver address is empty and its data field contains the compiled bytecode of the contract to be created (this makes sense — contracts can create contracts too). Let’s look at a quick example. Please open the directory of exercise 1; in it, you will find a contract called MyContract with the following code:

Read on >>>>