IVDeFi PRIMITIVES

Now that the DeFi infrastructure has been discussed in detail, this chapter describes the primitive financial actions that developers can use and combine to create complex dApps and the advantages each action may have over its centralized counterparts.

TRANSACTIONS

Ethereum transactions are the atoms of DeFi (and Ethereum as a whole). Transactions involve sending data or ETH (or other tokens) from one address to another. All Ethereum interactions, including each of the primitives discussed in this section, begin with a transaction. Therefore, how transactions work is an integral part of understanding Ethereum in particular and DeFi in general.

In Ethereum, there are two types of addresses: the externally owned account (EOA) and an address of a contract account. Transactions sent to an EOA can only transfer ETH.1 In Bitcoin, all addresses are EOA. In Ethereum, when data is sent to a contract account, the data are used to execute code in that contract. The transaction may or may not have an accompanying ETH payment for use by the contract.

A single transaction starts with an end user from an EOA but can interact with many dApps (or any Ethereum smart contract) before completing. The transaction starts by interacting with a single contract, which will enumerate all the intermediate steps in the transaction required within the contract body.

Clauses in a smart contract can cause a transaction to fail and thereby revert all previous steps of the transaction; ...

Get DeFi and the Future of Finance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.