0% found this document useful (0 votes)
12 views

IS4302_lecture 3_Fall 2024

Uploaded by

Xibo ooo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

IS4302_lecture 3_Fall 2024

Uploaded by

Xibo ooo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

IS4228: Information Technology and Financial Services

IS4302
Blockchain and Distributed
Ledger Technologies
Lecture 3

© Copyright National University of Singapore. All Rights Reserved.


Overview

• Smart Contracts
• Tokenization
• NFTs
• Important standards of Ethereum

2
Smart Contracts

• Smart contracts are contracts expressed as a piece of code that


are designed to carry out a set of instructions.
• However, there’s no middleman. There’s no person or
company holding your information or verifying it. The
blockchain verifies and holds information for you.
• Decentralized apps (Dapps) are a series of linked smart
contracts.

3
How does a smart contract work?

Imagine a conventional online transaction, without a smart contract.


Let's say you want to buy a car online. You’d need:

• 📇📇 A listing site to hold the information on all the cars you’d like
to see
• 📯📯 A way of communicating with sellers
• 💰💰 A payment system to allow you to exchange money once
you’ve found your car
• 💳💳 Some capacity to get a refund if the car turns out to be a dud
• � A way to register the change of car ownership with the
authorities

4
• 📇📇 A listing site to hold the information on all the cars you’d like to see
• 📯📯 A way of communicating with sellers
• 💰💰 A payment system to allow you to exchange money once you’ve found
your car
• 💳💳 Some capacity to get a refund if the car turns out to be a dud
• � A way to register the change of car ownership with the authorities

Each of these components requires a level of trust between you and the site or
service in question. In addition, each part of that process is typically controlled by
a different company or individual.
It wouldn’t take much for a sneaky person or organization to meddle with any of
the above elements, spoiling or voiding the whole process.

5
How does a smart contract work?

Smart contracts remove the need to trust multiple parties:

• 🔒🔒 Secure: They use cryptography to prevent the alteration of


records.
• 🔍🔍 Transparent: Everyone can see what the smart contract is
and what it’s being used for.
• 🙏🙏 Third-party free: Smart contracts don’t need a middleman to
verify them. The blockchain does that for you.
• 🤖🤖 Autonomous: They work automatically, so there's no wait
for human intervention.
• ✅ Accurate: Because smart contracts are written in code, they
have fewer gray areas than written or spoken languages.
6
How does a smart contract work?

Smart contracts automatically execute when pre-defined conditions


are met. The operation of a smart contract can be briefly described
with three main terms:

• 🤝🤝 Interconnectivity: Smart contracts possess a limited range of


functions. Interconnected smart contracts can create more
complex structures called decentralized applications (dapps).
• 💡💡 Objects: The signatories of this smart contract can modify its
terms, which determine how the subjects of the contract interact.
• 🌍🌍 Environment: Smart contracts depend on a secure
cryptographic environment to function safely, ensuring the data
they process is immutable and transparent.
7
Who is using smart contracts?

Smart contracts are at the heart of the entire decentralized finance


(DeFi) revolution
• They include decentralized exchanges, lending protocols and
synthetic derivatives.
• DeFi is a highly experimental and risky niche within the wider
cryptocurrency space.

Smart contracts power popular DeFi protocols like:


Compound (a company that allows people to earn money on the
crypto they save) , Aave, Uniswap, and hundreds of others.

8
Who is using smart contracts?

Smart contracts power popular DeFi protocols like:


• Compound: a company that allows people to earn money on
the crypto they save. Where Compound stands out is the
tokenization of the assets locked in their system through the
use of cTokens.
• Aave: Aave is a decentralized lending protocol that lets users
lend or borrow cryptocurrency without going to a centralized
intermediary. Users deposit digital assets into "liquidity
pools," which become funds that the protocol can lend out.

9
Who is using smart contracts?

They’ve also been adopted by corporations and some governments. Some of the
most prominent examples include:

• 🎮🎮 Ubisoft: Video games giant Ubisoft. Among its many blockchain


initiatives, it’s crafted specially-designed smart-contracts allowing users to
own, transfer, and claim rare non-fungible tokens (NFTs) based on its
popular Rabbids gaming franchise.

• 🏦🏦 ING: Dutch bank ING has co-created Fnality, a blockchain-based trade-


settlement system using smart contracts. It’s also involved in a number of other
blockchain initiatives.

• 🇸🇸🇸🇸 The Swedish government: Sweden’s government has tested a blockchain-


based land registry for proving the ownership of land, which is built on smart
contracts.
10
Overview

• Smart Contracts
• Tokenization
• NFTs
• Important standards of Ethereum

11
What are Crypto Tokens?

12
What are Crypto Tokens?

• Cryptocurrencies: digital representations of value


facilitated via blockchain technology.
• Crypto tokens: digital representations of assets that exist
on a blockchain.
• Enable investments, storing value, making purchases, or
raising capital

13
Coins vs. Tokens

• “Coins” use their own blockchains to keep track of data


• “Tokens”
• Use other people’s blockchain infrastructure
• No need to create a new blockchain or worry about validation
• Pay “rent” to that chain’s validators for the right to use it.
• Ethereum Blockchain:
• Both stores value and validates transactions

16
Benefits of Tokenization

Fewer Intermediaries:
• Traditional financial industry intermediaries not needed for
holding or trading crypto

Automation:
• In stark contrast to the traditional financial sector, most of the
bureaucratic procedures on a blockchain can be automated
using smart contracts.
• These algorithms can handle processes involving the exchange
of valuables, such as fiat money for stocks, tokens, or real
estate.
17
Some Types of Tokens

• Utility Token: used for the payment of services in dApps


• Governance Tokens: allows users to vote on running the
dApp
• Security Tokens: Create tokens for real-world investments,
e.g. tracked to the price of gold
• Platform Tokens: Given to those who invest in a crypto
platform
• Transactional Tokens: Used as a fast, easy way to transact
money

18
Utility Tokens

• Utility tokens are often referred to as user tokens or app coins.


• Utility tokens simply provide users with a product and/or
service.

19
Governance Tokens

• Give individuals governance rights over the protocol that they


subscribe to
• Enable voting, proxy voting, participation in governance
decision making, committee membership recruitment, and
more.

20
Security Tokens

What is a “Security”
• Any representation of an ownership position in a publicly-
traded corporation, or the ownership rights represented by an
option. In simpler terms, a security is any financial asset that
can be traded with a promise of returns.
• When a security has been issued to digitally to represent a real
tradable asset, it becomes a security token. These tokens serve
as a reference to the original asset/data.

21
Overview

• Smart Contracts
• Tokenization
• NFTs
• Important standards of Ethereum

22
NFTs: What Are Non-Fungible Tokens?

In brief
• Cryptographically unique tokens that are linked to digital (and
sometimes physical) content, providing proof of ownership.

• Use cases include:

including artwork, digital collectibles, music, items in video


games, KYC (Know Your Customer) procedures, academic
degrees and other educational certificates, collectibles, badges,
voting & elections, loyalty programs, copyright, supply chain
tracking, medical data, software licenses, warranties, and
more!
23
24
Early Use Case: Collectables

• CryptoKitties collectibles were some of the first non-fungible


tokens. Each blockchain-based digital kitten is unique;
• If you send someone a CryptoKitty and receive a CryptoKitty
from someone else, the one you receive will be a completely
different CryptoKitty from the one you sent. Collecting
different digital kittens is the point of the game.

25
Early Use Case: Collectables

CryptoPunks
• A series of 10,000 24x24 pixel art images depicting "punks" with
randomized attributes, including gender, headgear and eyewear.
• They're chiefly used for "flexing"—demonstrating membership
of an exclusive fraternity

26
Early Use Case: Collectables

Bored Ape Yacht Club


• Like CryptoPunks, there are 10,000 of them, each one has a
randomly generated set of attributes
• Owning a Bored Ape NFT also makes you eligible for drops of
additional NFTs

27
Uses: Collectables

Bored Ape Yacht Club


• The meta data stores the info that makes the NFT unique
• The data is stored as a tokenURI in the json format

• Both the tokenURI and image of this NFT are stored off chain
on IPFS
• InterPlanetary File System (IPFS) a protocol and file
sharing peer-to-peer network for storing and sharing data in
a distributed file system.
28
Overview

• Smart Contracts
• Tokenization
• NFTs
• Important standards of Ethereum

29
How Tokens Work in Ethereum

• Tokens rely on the Ethereum Blockchain


• They are fungible, meaning that each token is identical to
every other token of the same type.
• Often used as “utility tokens”
• Can represent: currency, shares of a company, loyalty
points, ownership of an asset

32
Ethereum standards ensure that
Importance of Ethereum all tokens on the network follow
Standards a set of rules and guidelines

Implementing standards enables


token compatibility with wallets,
exchanges, and other applications

Standards bridge interoperability


between applications, driving a
network effect for mutual gain

They simplify app development,


reducing costs and accelerating
time to market

33
Standard interfaces simplify user interactions
with tokens
Benefits of Ethereum
Standards

These enforce best practices enhance network


security

They make it easier to audit smart contracts


and ensure that they are functioning as
intended.

Standards reduce the risk of fragmentation in


the ecosystem and ensure that tokens can be
traded and used across different applications.

They create a level playing field for developers,


allowing smaller projects to compete with larger
ones on an equal footing.

34
Overview of Ethereum The most widely used standard is
ERC-20, which defines a common
Token Standards interface for fungible tokens.

ERC-721 and ERC-1155 are non-


fungible token standards that allow
for the creation of unique tokens
such as digital assets or collectibles.

Other Ethereum standards include


ERC-777, ERC-948, ERC-1400,
ERC-1967, and ERC-3000, which
address specific use cases such as
security tokens, gas token, or smart
contract upgrades.

35
Important standards
• ERC165 – method introspection
• ERC820#/1820 – contract registry
• Token standards:
• ERC20
• ERC721 – Non-fungible token
• ERC777 – improved ERC20
• ERC998 – composable NFT
• EIP1155/EIP1178*/EIP1203* – Multi-class token (FT or NFT
class)
• ERC137/181 – ethereum domain name service
• EIP1078* – universal login
• ERC1776** – meta transactions
• ERC1337** – subscription payment 36
ERC20

• Simple API to simulate a token using a smart contract.


Allow anyone to easily create a new token.
• totalSupply()
• balanceOf(address _owner)
• transfer(address _to, uint256 _value)
• transferFrom(address _from, address _to,
uint256 _value)
• approve(address _spender, uint256 _value)
• allowance(address _owner, address _spender)

37
What are ERC-20 Tokens?

• Tokens that rely on the Ethereum Blockchain


• They are fungible, meaning that each token is identical to
every other token of the same type.
• Can represent: currency, shares of a company, loyalty points,
ownership of an asset, etc.

38
What are ERC-20 Tokens?

• Smart contracts
• Create tokens: To get tokens, you send ETH to the smart
contract, which gives you tokens in return
• Handle Token Transactions
• Keep track of balances of each token holder

39
What are ERC-20 Tokens?

• Risks of Smart Contract Development


• Once a smart contract is deployed it cannot be changed
anymore
• Bugs could cause token loss or theft
• Interoperability
• To make tokens usable on exchanges or wallet, ERC20
was defined
• Defines 6 mandatory functions/methods

40
ERC20 Methods

• Simple API to simulate a token using a smart contract.


Allow anyone to easily create a new token.
• totalSupply()
• balanceOf(address _owner)
• transfer(address _to, uint256 _value)
• transferFrom(address _from, address _to,
uint256 _value)
• approve(address _spender, uint256 _value)
• allowance(address _owner, address _spender)

41
ERC20 Methods

• totalSupply()
• Defines the maximum tokens in circulation. When this is
reached, no more tokens will be created.
• balanceOf(address _owner)
• This function returns the balance of tokens owned by a specific
address (_owner).
• transfer(address _to, uint256 _value)
• Sends tokens from the total supply to the user
• transferFrom(address _from, address _to,
uint256 _value)
• Transfers tokens between any two users who have them

42
ERC20 Methods

• approve(address _spender, uint256 _value)


• Verifies that the contract can give a certain amount of tokens to a user,
taking into account the total supply.
• allowance(address _owner, address _spender)
• Same as approve but checks if one user has enough balance to send a
certain amount of tokens to someone else

43
Example of how to implement an ERC-20 token
in Solidity:

44
ERC721 (Non-fungible token)

• Fungibility - property of a good or a commodity whose


individual units are essentially interchangeable, and each of its
parts is indistinguishable from another part.
• Non-fungible token – represent something unique
• ERC721 tokens are commonly used for digital art, collectibles,
and in-game assets. E.g. Crypto Kitties DNA

45
ERC721 (Non-fungible token)

46
ERC721 (Non-fungible token)

47
ERC721, Main differences to ERC-20

• function ownerOf(uint256 _tokenId) returns (address)


• Returns the address of the owner of the specified token ID (_tokenId).

• function transferFrom(address _from, address _to,


uint256 _tokenId)
• Transfers ownership of the specified token (_tokenId) from the sender (_from)
to the specified address (_to)

• function safeTransferFrom(address _from, address _to,


uint256 _tokenId)
• Has additional safety checks and the ability to pass along data.

• uint256 is an identifier for each unique token (vs just a ‘balance’ in


ERC-20)
48
difference between
transferFrom() and
safeTransferFrom()
Transfer token ownership
with ERC721's
transferFrom() and
safeTransferFrom()

safeTransferFrom()
checks validity, then transfers
token only if checks pass.
Otherwise, transfer reverts.`

49
ERC721 (Non-fungible
token)
Safe version of transfer
performs a
supportsInterface()
check before transfer
(ERC-165)

Previously, many token


‘lost’ due to erroneous
transfer to contract
address, which has no way
to ‘use’ token properly

50
Example Implementation

Implementing ERC721
with the OpenZeppelin
Library.

The contract is named


MyNFT and extends the
ERC721 contract.

Uses the “Counters”


library to keep track of
unique token IDs.

51
Example Implementation

The mintNFT() function is


a custom function that
we've added to our
ERC721 contract.

This function allows


minting a new NFT with a
given tokenURI and
transfer it to a specified
recipient.

It uses the _mint() and


_setTokenURI()
functions provided by the
ERC721 contract to create
a new token and associate
it with the given tokenURI.
52
ERC998 (Composable NFTs)

• ERC998: A standard for creating complex NFTs on the


Ethereum blockchain.
• Make NFT-based apps simpler with composable NFTs that can
be easily assembled and disassembled.

53
ERC998 (Composable NFTs)

• ERC721 as a ‘tree’
• Allow for child → parent, parent → child
• Transferring asset as a tree/subtree

• Use case:
• Bundle physically connected assets
• Game players can own NFTs that contain other NFTs
representing characters, items, and locations.
• Complex financial instruments based on NFTs, such as
collateralized debt obligations (CDOs) or tokenized funds that
contain a variety of different NFTs.
54
ERC998 (Composable NFTs)

• Key features for composable NFTs


• Add and remove child tokens
• Query child tokens
• Transfer parent tokens along with their child tokens.

55
ERC998 (Composable NFTs)

• ERC998 introduces transferChild(),


transferChildToParent(), and transferParent()
methods, allowing transfer of child and parent tokens between
addresses and contracts.
• rootOwnerOf() method allows you to query the ultimate
owner of a given NFT, even if it is contained within another
NFT.

56
ERC1155/1178*/1203*(Multi-class token)

• Combines ERC20 + ERC 721


• Multiclass fungible token
• Can represent multiple different assets or fungible tokens
within a single contract.
• ERC1155, ERC1178, and ERC1203 all provide different
approaches to implementing multi-class tokens, but they all
share the same goal of enabling greater flexibility and
efficiency in tokenized asset management.

57
ERC1155/1178*/1203*(Multi-class token)

• ERC1155/1178/1203 offers:
• Create and trade multiple fungible & non-fungible tokens
within a single contract
• Simpler token management & lower gas costs
• On-chain royalty payments for token creators to share in
revenues generated.

Token ID Address Balance


111 Alice 3
(Supply = 6, Bob 1
Fungible)
Chuck 2
222 (Non-fungible) Alice 1
58
ERC1155 vs ERC20 and ERC721

• Main difference to ERC20, ERC721:


• function safeTransferFrom(address _from, address _to,
uint256 _id, uint256 _value, bytes calldata _data)
external
• ERC1155 tokens use the safeTransferFrom() function to transfer
tokens, which takes in five arguments: the address of the token
sender, the address of the token receiver, the identifier for the
token class being transferred, the value being transferred, and
any additional data that may be included. In contrast, ERC20
tokens use the transfer() function to transfer tokens, which only
takes in two arguments: the address of the token receiver, and
the value being transferred.
• uint256 identifier for each token class
• uint256 value for each token class

61
ERC1155/1178*/1203*(Multi-class token)

• Safe version of transfer which performs a


supportsInterface() check before transfer (ERC-165)

• function safeBatchTransferFrom(address _from,


address _to, uint256[] calldata _ids, uint256[]
calldata _values, bytes calldata _data) external

62
ERC1078 - Universal Login

• ERC1078: A decentralized self-sovereign identity system for


users to maintain a single online identity.
• Implemented on the Ethereum blockchain for secure
management of identities across multiple applications and
services.
• Enables users to create a unique digital identity, accessible
anywhere that supports the standard.

63
Generate a unique Ethereum address
associated with a public key using
ERC1078 identity.
How ERC1078 Works

Set up profile with name, email, etc.

Log in to any app/service supporting


ERC1078 by signing a message with
private key - verifying the signature
against public key in blockchain.

Take control of your data - revoke


access to apps/services anytime.

64
ERC1078*(Universal login)

• Using on-chain identity proxy as a contract (EIP725)


• execute arbitrary contract calls
function execute(uint256 _operationType, address _to,
uint256 _value, bytes _data)

• hold arbitrary data


getData(bytes32 _key), setData (bytes32 _key, bytes _value)

• Can act as on-chain owner of all kinds of token

• Address of proxy using ENS (ERC165)


65
ERC1078*(Universal login)

• Having ephemeral handles to proxy contract


• Multiple devices as handle to contract
• Define multi-sig condition
• Able to define transaction classes / limitations
• Social recovery (defined social network who can help
recover)

• Remove reliance on single ‘cold’ recovery (user-unfriendly)

66
Subscription payment (ERC1337**)

• Regular subscription payment using smart contract.


“Standing order” as smart contract
• User defined schedule
• User able to cancel at any time
• Helps ensure recurring income for business owners

67
How ERC1337 Works

• When a user subscribes to a service or product that supports


ERC1337, they authorize the service provider to deduct a
certain amount of Ether from their account at regular intervals.
• The subscription contract is stored on the blockchain and
includes information such as the subscription period, the
amount of Ether to be deducted, and the address of the service
provider.
• Once the subscription contract is in place, the service provider
can collect payments automatically without the need for the
user to manually initiate each payment.

68
Conclusion

1. Smart contracts are self-executing code on the blockchain,


eliminating intermediaries and enabling decentralized apps
(Dapps) to operate autonomously and securely.

2. Tokenization digitizes assets on blockchains like Ethereum,


streamlining transactions by automating processes and reducing
reliance on traditional financial intermediaries.

3. Ethereum’s token standards, like ERC20, are essential for


creating and managing digital assets, ensuring interoperability,
security, and efficiency in decentralized applications.

69
Thank you!

70

You might also like