DeFi and the future of the global economy: What even is DeFi?

Federico Reyes Gómez
4 min readFeb 28, 2021

Sample ERC20 Token Contract Interface (https://ethereum.org/en/developers/tutorials/understand-the-erc-20-token-smart-contract/)

This blog post is be split up into four sections:

  1. What is Decentralized Finance (DeFi)? (You are here!)
  2. Application 1: Decentralized Exchanges
  3. Application 2: Stablecoins and DAOs
  4. Application 3: Lending Platforms

Part 1: What even is Decentralized Finance (DeFi)?

Most people have now heard of cryptocurrencies, the new FinTech craze. Whether it’s due to Tesla’s $1.5B investment in Bitcoin (BTC), the rise of meme token Dogecoin built on the Ethereum (ETH) network, cryptocurrencies are all the rage these days. Cryptocurrencies are just the start, however. The real innovation lies in the underlying technologies, blockchains.

Blockchains are trustless digital databases managed using a distributed system of computation.

Their most basic and intuitive use is as a system of managing digital currencies like BTC and ETH. In the case of digital currencies, the database stores the users (addresses) and how much of the digital currency they own. Money moves around when users submit transactions to authorize buying, spending, or transferring some of the digital currency they own. Miners receive these transactions, verify them, and apply them to the system via various kinds of consensus protocols that allow millions of people around the world to agree on the state of the blockchain without needing to trust anyone at all.

One could also envision various different uses for blockchains: storing files (FileCoin), hosting medical data privately and securely (MedRec), and revolutionizing music licensing and payouts for artists.

While Bitcoin was the pioneer in the space, it’s limited scripting language restricted it to managing the digital currency, leading Ethereum’s scripting language, Solidity, to take center stage in the DeFi revolution. Solidity is a turing-complete scripting language designed for managing the state of the blockchain. Solidity scripts run on a sandboxed Ethereum Virtual Machine (EVM) as Smart Contracts, distributed public APIs that anyone can view, audit, and call in order to make changes to the state of the Ethereum blockchain.

For example, I might have a smart contract that allows users to vote for different candidates

pragma solidity ^0.4.22;/// @title Voting Smart Contract.
contract Ballot {
// A key-value store to keep track of votes
mapping(string => uint) public votes;
// A key-value store to make sure people don't double vote
mapping(address => bool) public voted;
// A list that keeps track of all candidates
string[] public candidates;
// Create a new ballot to choose one of the candidates.
constructor(string[] initialCandidates) public {
candidates = initialCandidates;
}
// Give your vote to the candidate
function vote(string candidate) public {
// Make sure that the person calling this contract
// (msg.sender) hasn't voted yet
if (voted[msg.sender] == false) {
// Add a vote for this candidate
votes[candidate] += 1
// Register this citizen as having voted
// so they can't try to vote again
voted[msg.sender] = true
}
}
// Check who the winner is
function getWinner() public returns(string) {
// Check the votes for all of the candidates
winningCandidate = candidates[0];
winningVotes = votes[winningCandidate];
for (uint i = 0; i < candidates.length; i++) {
currentCandidate = candidates[i];
currentVotes = votes[currentCandidate];

// If this candidate has more votes than the current
// leader, make him the leader
if (currentVotes > winningVotes){
winningCandidate = currentCandidate;
winningVotes = currentVotes;
}
}

return winningCandidate;
}
}

We just need to keep track of the candidates, the number of votes they have, and which citizens have voted. We then let users vote for a candidate using the vote() function (bonus: we can even enforce they don’t vote twice!) and we can check the winner using the getWinner() function. (Note that this is a dummy contract for pedagogical purposes. In a real application, you’d want some way of deciding when the winner can even be called, etc).

As you can see, the functionality in these smart contracts can be arbitrarily complex! This allows us to develop applications of arbitrary complexity. This has led to the rise of Decentralized Finance applications, smart contracts that allow users to perform various standard finance operations in a trustless, distributed fashion. Popular DeFi applications include

  1. Decentralized Exchanges (Exchange one Cryptocurrency for another)
  2. Stablecoins (A cryptocurrency whose price is ‘pegged’ to an external currency)
  3. Lending (Peer-to-peer lending infrastructure for lenders to earn interest and borrowers to borrow cryptocurrencies without needing a bank approval)

I will go over these in parts 2, 3, and 4 of this blog!

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response