02 - Exploring Smart Contracts

Smart Contracts in Practice

Before we dive into writing smart contracts of our own, let’s take a look at some of the simpler contracts that are alive and well on the Ethereum blockchain today. Many of these contracts implement another currency or token on top of Ethereum, and are therefore often called “Ethereum (based) tokens”. Because this use case is so popular, there are a few different token standards that have arisen and gained popularity.

These standards merely formalize requirements for a contract’s behavior and interface, so they don’t (necessarily) provide or require any precise implementation of logic in order for the contract to conform to the specification. Think of these standards more like official interface definitions (like Java interfaces).

By far, the two most well-known token standards are ERC-20 and ERC-721.1 These standards and their derivatives are the most popular for Ethereum-based fungible and non-fungible tokens, respectively.

Fungibility

Fungibility is a property of an asset that describes its interchangability.

If the asset is fungible, that means that it can be replaced with another of the same type of asset and no value will be lost or gained. A fungible asset would be like a dollar: it doesn’t matter which dollar you have—one dollar is one dollar. In other words, when dealing with fungible assets, what matters is quantity.

Non-fungible assets, on the other hand, are not universally mutually equivalent. Instead, a non-fungible asset is unique from all of the other assets, and which assets you own matters. A non-fungible asset would be like a piece of artwork: it matters significantly what you own—who created it, when, what media, whether it is an original, etc. This means that the quality of non-fungible assets you own usually matters more than the quantity.

ERC-20: Fungible Tokens

An ERC-20 token contract provides an interface to a fungible token, associating Ethereum addresses with a quantity of tokens. The smart contract maintains the collection of address-balance associations and provides a set of public operations that can be performed on the collection.

Some of the operations provided by an ERC-20 token contract include:

  • name – Returns the name of the contract’s token
  • totalSupply – Returns the total number of tokens managed by the contract
  • transfer – Transfers a quantity of tokens from one address to another address
  • balanceOf – Returns the number of tokens owned by an address

Sample Implementations

Live Contracts

Note: These contracts were selected for their relative simplicity and readability. We do not necessarily endorse any of these tokens or projects.

Issues

ERC-721: Non-fungible Tokens (NFTs)

An ERC-721 token contract provides an interface to an NFT token registry, wherein unique token identifiers are associated with their owner’s ETH address. The public interface is reminiscent of some of the ERC-20 methods, with some interesting modifications and additions:

  • transferFrom – Transfers a single token from one address to another
  • ownerOf – Returns the address of the owner of a specific token

Sample Implementations

Live Contracts

Note: These contracts were selected for their relative simplicity and readability. We do not necessarily endorse any of these tokens or projects.

Issues

Other Contracts

Project Status Update

Given some of these example smart contracts, you should start thinking about what you might want your project to look like. You project must contain a smart contract and web front-end at least. It does not have to be complicated, but it should be usable by a general audience. Here are some more ideas for consideration:


  1. ERC: Ethereum Request for Comments ↩︎

  2. Not an endorsement of this project or its practices. ↩︎