0% found this document useful (0 votes)
2K views

Intro To Web3

Web3 is the latest iteration of the internet that provides users with full ownership and control over their data and digital assets without centralized authorities. It builds on Web2 by adding blockchain-based functionality for decentralized data ownership and transactions. Blockchain serves as the underlying technology, providing an immutable record of transactions distributed across a network of nodes without a central point of control. This allows for open, trustless, and permissionless interaction between users.

Uploaded by

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

Intro To Web3

Web3 is the latest iteration of the internet that provides users with full ownership and control over their data and digital assets without centralized authorities. It builds on Web2 by adding blockchain-based functionality for decentralized data ownership and transactions. Blockchain serves as the underlying technology, providing an immutable record of transactions distributed across a network of nodes without a central point of control. This allows for open, trustless, and permissionless interaction between users.

Uploaded by

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

Intro to Web3

Day 1: Intro to Web3


What is Web3

To put it simply, Web3 is the latest version of what we know as the internet. In this
version, people have full ownership of their content, data and assets. 

There are also no middlemen involved, which is presently the case with large
corporations and governments controlling and regulating whatever goes on the
internet. 

In some areas, you may read some terms like decentralized and democratization of the
internet being used for Web3, which can be sort of confusing. But for now, think of
decentralization as not being controlled and monitored by others, rather, by yourself. 

Web1 = read 
Web1 happened when the internet was officially introduced in the 1980s onwards.
Few individuals or groups created content - like news media outlets, search engines,
directories. During this era, the majority of traffic used the internet in a read-only
capacity. They searched for an article, read it and closed it, that’s mostly how far it
went. Very little participation. 

An example of Web 1 = Yahoo.com

Web2 - read, write


Web2 came about in the 2000s and is still pretty much there. Now users like me and
you can share our thoughts on that article we read, and that too, amongst our friends
on social networks. It made space for everyone to become a content creator and
consumer simultaneously - although those of us who gathered followerships only got
paid. Now media is produced on social networks, who then are able to sell personal
data to advertisers in order to generate massive amounts of revenue. But since they
collect a lot of our personal data, privacy has started to become a concern.

An example of Web2: YouTube

Web3 - read, write, own


Since privacy and personal data became a concern, Web3 solves that. With Web3,
participants will have full ownership over their content, data, and assets. It represents
a democratized Internet – an Internet that is governed by users for the benefit of users.
Right now everything is controlled by the people at the top - in Web3, they may not
exist. Even if they do, you won’t need them because you’ll own what you create. 
An example of Web3: Mirror.xyz 

Expanding more into this, Web3 will give users full ownership of their assets, data,
practically anything via blockchains. 

Now, what are blockchains? 


Blockchain is a public list of records. It stores information in batches called blocks.
These blocks are linked together to form a continuous line. A chain of blocks. A
blockchain. Each block is like a page of a record book. 

What isn’t blockchain

Blockchain is NOT a cryptocurrency.

Blockchain is NOT a programming language.

Blockchain is NOT a cryptographic codification.

Blockchain is NOT an AI or Machine Learning technology.

Blockchain is NOT a Python library or framework.

Nope, nada, naa. 

Let’s move on. But before I mention the word I’m about to,

Here’s the definition for immutable: unchanging over time or unable to be changed

Synonyms include: fixed - set - unchangeable - rigid - unshakeable - irremovable 

So, again, what does blockchain do for me?

It works as an immutable (fixed, unchangeable, unshakeable) record of transactions


that do not require to rely on any external authority like banks, governments, large
corporations to validate the authenticity and integrity of the data. 

As I mentioned earlier, Blockchain is a public database of information, that means


there is no central body or single entity control (say Mark Zuckerberg) managing and
controlling the database and evil laughing. 

In fact, millions of users on the Internet help manage and maintain the records. 
That’s decentralized and democratized for you, hah, take that Facebook!

So in a nutshell, these changes will create an open, trustless, and permissionless


network. Let me explain if this sounds wild to you.

Open: It will be an open-source software built by an open and accessible community


of developers and executed in the full view of the world.

Trustless: It will allow participants to interact publicly or privately without any third
party butting in.

Permissionless: Neither users nor suppliers need any authorization from a governing


body for participating.

Day 2: Intro to Blockchain Theory and Consensus Mechanism

What is a Blockchain?

Everyone is talking about cryptocurrencies, blockchain, NFTs, Bitcoin, Ethereum, Shiba INU, etc. All
these topics have become trendy, and there's a lot of information about them on the internet. But,
what does it mean? Why is everyone talking about them? What makes them so demanding and
popular?

In this lesson, we will talk about blockchain as it is the underlying technology behind all this.

But, before defining a blockchain, let's try to understand the reason why we need a blockchain? And
what problems does it solve?

To understand why we need a blockchain, first, let's try to understand the meaning of "centralized
systems".

A centralized system is a network of computers that depend on the main computer (i.e. central
point), also known as a server. All the data is stored and controlled by this server.

But, what is wrong with a centralized system? What are the problems that a centralized company
could face in the long run? Here are some of them:

The nodes (i.e. computers) participating in this network depend on a single server. So, this provides
hackers with a small surface area which makes it easier for them to attack and exploit a server.

A server is controlled by a few people of an organization who could always exploit the server. Thus, a
server is prone to get attacked by the internal members of an organization.

Servers are highly dependent on a network connection. If a server goes down due to connectivity
issues then all the nodes depending on that server go down with it.

Now, let's focus on how blockchain technology can solve these problems.

Blockchain is a decentralized network. Hence, it does not have a central authority responsible for
managing and distributing data. Instead, the data is distributed (i.e. duplicated) to the nodes
participating in this network.
The participating nodes are the ones who manage a blockchain network. So if any node tries to
change the data, then this modification has to be validated by the other nodes. And, if the other
nodes find out that this modification is incorrect then they will reject it.

Blockchain can tackle network issues as it consists of many nodes. So, the entire network won't be
affected if a single node goes down. 

So, what does the term "blockchain" mean?

Blockchain is a public database for storing real-world data, shared and updated with many nodes
(computers) across the globe. In technical terms, blockchain is a collection of blocks linked to each
other. 

Let's break this down in simple terms. The word "blockchain" consists of two parts: block and chain.

"Block" is an entity that stores any real-world data. For our convenience, let's assume that a block
stores the transactions happening on the internet. If Holly sends 5 ETH (Ethers) to Molly, this
transaction needs to be added to a block to be successful.

"Chain" can be defined as a cryptographic link of a block with the previous block. In other words, the
link between blocks forms a chain of blocks. So, to sum it up, blockchain is a collection of blocks
chained together using cryptography.

Features of Blockchain

Blockchain is an immutable(unchangeable, ) data storage that is

Decentralized: There is no central authority that controls the blockchain. Blockchain is a distributed
technology and it is not controlled by anyone.

Peer To Peer: Blockchain is a distributed technology shared among the nodes (i.e. peers)
participating in the network. 

Trustless: The word "trustless" is a fundamental part of blockchain technology. People have always
been dependent on third-party organizations such as banks, people or any other intermediaries. But
with blockchain technology, people don't have to rely on any third party for their transactions and
holdings.

Secure: Blockchain uses decentralization, cryptography and consensus at its core which makes it
secure.

How does blockchain work?

Every blockchain begins with a Genesis Block, and it is the first block of a blockchain. A Block is
limited in size and can store a limited number of transactions.

Let's assume that we have three blocks with some transactions stored in them. To link these blocks,
every block is assigned with a unique hash id that is generated using the data present in that block.
So when someone tries to modify a Block, the hash id of that block changes as well.

Now, the hash id of the first block is stored in the second block. And the hash id of the second block
is stored in the third block. This process is repeated for all the subsequent blocks. Thus, we have a
chain of blocks referred to as the "blockchain".

By the way, this is what a hash id looks like for "Molly sends 5 ETH to Holly".
848C68F9EDF7EFFDA27005EFD643F785030C77B79E5637D92CB6A7D516A27370

"Molly sends 5 ETH to Holly" is an example. In a real-world case scenario, it could be a transaction.

What does ETH mean?

ETH is the symbol for Ether cryptocurrency. Ether is the native currency of the Ethereum blockchain.

Every blockchain has its own currency that users can use to make transactions. For example, the
currency supported by the Bitcoin blockchain is Bitcoin.

What are Blockchain Layers?

Layer 0

Layer 0 of a blockchain network consists of components such as the internet, hardware, and
connections that support the smooth functioning of Layer 1.

Layer 1

A layer one protocol also known as an "implementation layer", refers to the core architecture of a
blockchain network. It forms the foundational base of any blockchain network. A layer one protocol
defines a set of rules for operations like transaction throughput, block time, consensus algorithm,
etc., that governs the entire network. For example, Ethereum is temporarily using a proof-of-work
(PoW) consensus algorithm before transitioning to a proof-of-stake (PoS) network. 

Layer 2

Layer 2 is a framework that provides a full-fledged solution to Layer 1 to improve its overall
performance.

Why do we need Layer 2?

Currently, Layer 1 is facing problems such as low transaction throughput (i.e. no. of transactions per
second) and performance due to the increasing number of users. Layer 1 uses the proof-of-work
(PoW) consensus algorithm that requires high computational power. This approach is more secure,
however, affects the performance.

To solve this problem, Layer 2 acts like a third-party integration that works in conjunction with Layer
1. With this, a part of the work that has to be done by Layer 1 will be done by Layer 2. Layer 2 will
still be following the protocols of Layer 1 while carrying out the work.

Some examples of Layer 2 solutions are Polygon Matic for Ethereum and Bitcoin Lightning Network
for Bitcoin.

Layer 3

Layer 3 is a layer on top of Layer 1 and Layer 2 that enables the development of applications also
known as decentralized applications (Dapps). This layer hosts these applications and also defines the
protocols for them.

In simple words, this layer allows users to interact with a blockchain.

Bitcoin is not a programmable blockchain, which means that it does not support decentralized
applications. Whereas, blockchains such as Ethereum and Solana have become the best platforms
for developing decentralized applications. 
Popular Blockchain Networks

Bitcoin

Bitcoin is a digital currency that uses blockchain technology to record its transactions. It was created
in January 2009 by a mysterious guy named Satoshi Nakamoto.

Ethereum

Ethereum is a blockchain technology powering its currency (i.e Ethers) and many decentralized
applications. As discussed earlier, it's a programmable blockchain that supports many applications in
different domains. It was created in July 2015 by Vitalik Buterin. 

Binance

Binance started as a marketplace for trading crypto assets. It supports its cryptocurrency (i.e. BNB).
In the beginning, BNB was dependent on the Ethereum blockchain, but now has its own blockchain
known as Binance Chain. Binance was founded in 2017 by Changpeng Zhao.

Solidity

Day 3: Intro to Ethereum and its terminologies

Introduction

Odds are you’ve heard about the Ethereum blockchain, whether or not you know what it is. It’s been
in the news a lot lately, including the cover of some major magazines, but reading those articles can
be like gibberish if you don’t have a foundation for what exactly Ethereum is. So what is it? In
essence, it's a public database that keeps a permanent record of digital transactions. Importantly,
this database doesn’t require any central authority to maintain and secure it. Instead, it operates as
a “trustless” transactional system — a framework in which individuals can make peer-to-peer
transactions without needing to trust a third party OR one another.

Still confused? That’s where this post comes in. My aim is to explain how Ethereum functions at a
technical level, without complex math or scary-looking formulas. Even if you’re not a programmer, I
hope you’ll walk away with at least a better grasp of the tech. If some parts are too technical and
difficult to grasp, that’s totally fine! There’s really no need to understand every little detail. I
recommend just focusing on understanding things at a broader level.

Many of the topics covered in this post are a breakdown of the concepts discussed in the yellow
paper. I’ve added my own explanations and diagrams to make understanding Ethereum easier. 

Blockchain Definition

A blockchain is a “cryptographically secure transactional singleton machine with shared-state.” [1]


That’s a mouthful, isn’t it? Let’s break it down.

 “Cryptographically secure” means that the creation of digital currency is secured by complex
mathematical algorithms that are obscenely hard to break. Think of a firewall of sorts. They
make it nearly impossible to cheat the system (e.g. create fake transactions, erase
transactions, etc.)

 “Transactional singleton machine” means that there’s a single canonical instance of the
machine responsible for all the transactions being created in the system. In other words,
there’s a single global truth that everyone believes in.
 “With shared-state” means that the state stored on this machine is shared and open to
everyone.

Ethereum implements this blockchain paradigm.

The Ethereum blockchain paradigm explained

The Ethereum blockchain is essentially a transaction-based state machine. In computer science, a


state machine refers to something that will read a series of inputs and, based on those inputs, will
transition to a new state.

With Ethereum’s state machine, we begin with a “genesis state.” This is analogous to a blank slate
before any transactions have happened on the network. When transactions are executed, this
genesis state transitions into some final state. At any point in time, this final state represents the
current state of Ethereum.

The state of Ethereum has millions of transactions. These transactions are grouped into “blocks.” A
block contains a series of transactions, and each block is chained together with its previous block.
To cause a transition from one state to the next, a transaction must be valid. For a transaction to be
considered valid, it must go through a validation process known as mining. Mining is when a group
of nodes (i.e. computers) expend their compute resources to create a block of valid transactions.

Any node on the network that declares itself as a miner can attempt to create and validate a block.
Lots of miners from around the world try to create and validate blocks at the same time. Each miner
provides a mathematical “proof” when submitting a block to the blockchain, and this proof acts as a
guarantee: if the proof exists, the block must be valid.

For a block to be added to the main blockchain, the miner must prove it faster than any other
competitor miner. The process of validating each block by having a miner provide mathematical
proof is known as a “proof of work.”

A miner who validates a new block is rewarded with a certain amount of value for doing this work.
What is that value? The Ethereum blockchain uses an intrinsic digital token called “Ether.” Every
time a miner proves a block, new Ether tokens are generated and awarded.

You might wonder: what guarantees that everyone sticks to one chain of blocks? How can we be
sure that there doesn’t exist a subset of miners who will decide to create their own chain of blocks?

Earlier, we defined a blockchain as a transactional singleton machine with a shared state. Using this
definition, we can understand the correct current state is a single global truth, which everyone must
accept. Having multiple states (or chains) would ruin the whole system because it would be
impossible to agree on which state was the correct one. If the chains were to diverge, you might
own 10 coins on one chain, 20 on another, and 40 on another. In this scenario, there would be no
way to determine which chain was the most “valid.”

Whenever multiple paths are generated, a “fork” occurs. We typically want to avoid forks, because
they disrupt the system and force people to choose which chain they “believe” in.
To determine which path is most valid and prevent multiple chains, Ethereum uses a mechanism
called the “GHOST protocol.”

“GHOST” = “Greedy Heaviest Observed Subtree”

In simple terms, the GHOST protocol says we must pick the path that has had the most computation
done upon it. One way to determine that path is to use the block number of the most recent block
(the “leaf block”), which represents the total number of blocks in the current path (not counting the
genesis block). The higher the block number, the longer the path and the greater the mining effort
that must have gone into arriving at the leaf. Using this reasoning allows us to agree on the
canonical version of the current state.

Day 4: Writing Hello World Contract using remix

Day 4: Write HelloWorld Contract using Remix

Hey fam, I am Ismail Vohra, I am back and will be leading this drip from this day onwards. I
understand that writing a smart contract is quite a tedious job for novice programmers. There is a
plethora of information and tutorials out there and you are probably confused about not knowing
where to start. You are surrounded by all of these exquisite and alien terms which have got you
wondering where to start? What IDE I should use? Well, you don't need to worry anymore. This is
the guide we wish existed when we first started out writing smart contracts. Regardless of whether
you are a complete novice or a seasoned professional, this is the only guide you'll ever need to get
started on your first contract. Let's begin by brushing up on some basics regarding some
terminology.
What is Remix IDE?

An IDE is an Integrated Development Environment for enabling the development of smart contracts
via Solidity. Does this ring a bell? No? Well, we were in the same boat too back then, but let us
simplify some key components. In layman's terms, an IDE is a software for building applications that
combines common developer tools into a single GUI. Remix is a popular IDE for Ethereum Smart
Contract development written in JavaScript and supports complete testing, deploying, and
debugging of all smart contracts. There are a bunch of ways to access Remix:

1. You can either use your browser to access it via https://remix.ethereum.org/

2. You can install it on your system too by clicking the following link

3. The final option is to use the ETH Dapp browser called Mist

Now let's get started with the process you dread the most. This article is all about teaching you how
to write your first smart contract, so don't worry we will not hesitate to simplify and elaborate points
down to the very basics and fundamentals of how these things operate. In addition to this, keep in
mind, that there are no dumb questions, only dumb answers. So don't shy away from expressing
your curiosity.

Getting Started with Writing Your First Hello World Contract

Let us begin now with our ''Hello World'' contract in Remix. We will aim to print and amend "Hello
World" on the screen and learn some key aspects about smart contracts on the way. You have to
carefully follow the steps below to avoid any additional hassle. Let's get started:

Head over to http://remix.ethereum.org/ on your browser to launch Remix IDE. You will be
presented with the following screen:

Click on the file explorer tab indicated by the white arrow in the image above. Select Solidity as the
default environment (if prompted) and then click on the plus icon next to the browser (indicated by
the white arrowhead)
Name your file as ' 'HelloWorld.sol'' (whereby ".sol" refers to Solidity programs).

For pro engineers who wish to jump directly to the complete code, here's a copy for you:

//SPDX-License-Identifier: UNLICENSED

pragma solidity >= 0.8.0;

contract HelloWorld {

event messagechanged(string oldmsg, string newmsg);

string public message;

constructor(string memory firstmessage) {

message = firstmessage;

function update(string memory newmesssage) public {


string memory oldmsg = message;

message = newmesssage;

emit messagechanged(oldmsg, newmesssage);

Now let's formally get started:

Since our Solidity contract is not licenced, it is a good practice to declare it as comment in the first
line of code:

//SPDX-License-Identifier: UNLICENSED

We then declare the compiler version of Solidity for our contract. As an arbitrary number, we choose
greater than 0.8.0

pragma solidity >= 0.8.0;

We then declare the name of our contract, "Hello World" as follows:

contract HelloWorld {}

We then declare a public variable called "message" of type "string" to hold the most up-to-date
value of our message. Ethereum offers a built-in data type called "event" for debugging purposes. It
is similar to "console.log" in JavaScript except that it is emitted during transactions on Ethereum and
stored in its blockchain. In our case, since we'll be amending the value of our "message" from "Hello
World" to "Hello Metaschool" later, it would be a good practice to store the value of our old and
new message in an event whenever the value changes

event messagechanged(string oldmsg, string newmsg);

string public message;

A constructor in Solidity is the piece of code that is required and executed at the time of deployment
of the contract. We declare our constructor and take a string "firstmessage" as input and assign it to
our "message" variable. What this means is that when the contract is deployed, it will ask for an
initial message to get started with.

constructor(string memory firstmessage) {

message = firstmessage;
}

At the time of deploying the contract, we will pass '' Hello World" as the first message so the value
of the string public message will become updated.

We now need a means to update the value of our "message" whenever required. For this purpose,
we write a function called "update" which takes our "newmessage" as input.

function update(string memory newmesssage) public {

We then declare a temporary variable (notice "memory") to store the value of our current
"message". We then update the value of the "message" to the "newmessage" and emit our earlier
declared event "messagechanged" to keep a track of changes on the blockchain:

function update(string memory newmesssage) public {

string memory oldmsg = message;

message = newmesssage;

emit messagechanged(oldmsg, newmesssage);

The programming part of our tutorial is now complete. It is time to compile our contract. Click on
Solidity Compiler in the left-hand corner (Highlighted in Yellow):
Then without changing any prior setting click on '' Compile HelloWorld.sol''. After successful
compilation, click on "Deploy and run transactions" in the navbar below Solidity Compiler:
You don't have to change any settings, just pass in "Hello World" and click "Deploy". You will observe
your contract appears in the ''Deployed Contracts Tab''. Our Hello World contract is now deployed
on our local Virtual Machine. Time to test it out:

Click on the downward arrow next to your contract and you will see two options, "update" and
"message". Click on the "message" to see the latest value stored in our "message variable":
Hello World. Yayy! Now let's use the "update" function and pass in "Hello Metaschool". Fetching the
latest value of "message" should now display as follows:

Congratulations, you have managed to write and run your first smart contract in Solidity. Happy
Coding!
Day 5: Creating your own Simple ERC-20 Contract

Day 5: Creating your own Simple ERC-20 Contract

As discussed earlier, Blockchains are well recognized for their critical function in keeping a secure
and decentralized record of transactions in cryptocurrency systems like Bitcoin and Ethereum. With
this crypto craze taking over the world right now, people are eager to know how to create their own
(often tradeable) tokens. As Smart Contracts allow the freedom to engineers to code what and how
they like it, it is imperative that standards are required for fungible tokens. Today, we will discuss the
most popular standard for fungible tokens, ERC-20, and writing the code for your first token using
this contract.

What is the ERC-20 Standard?

Tokens represent a wide range of digital assets in the Ethereum system, including vouchers, IOUs,
and even real-world, actual things. Ethereum tokens are essentially smart contracts that run on the
Ethereum network. ERC-20 is one such token that emerged as the trending standard for the majority
of smart contracts. It enlists various rules and regulations that all ETH-based tokens have to follow.
These include how token ownership can be transferred and how transactions are approved.

As a result, this token enables all sorts of developers to precisely forecast how future tokens will
behave within the Ethereum system. This simplifies the process for developers since they can
continue working knowing that no new projects will need to be performed every time a new token is
published, as long as the token satisfies the rules. This compliance is also required since it assures
that the many various Ethereum tokens are compatible. Now that we have brushed some basics
regarding token standards, let us get into creating the ERC-20 contract.

Getting Started with Creating ERC-20 Smart Contract

Now that we have brushed up on some basics about ERC-20 and the crucial role it plays in token
creation, let us move toward the process of creating one. This is going to be an easy-to-follow
tutorial where you will learn to write a simple ERC-20 token. For those of you who want to jump
right to the complete code, you can skip to this section. Let's get started.

 We are going to name our token, which is ''VOH Coin" in this case

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.0;

contract VOHCoinERC20{}

 In the initial line of code, we define the license identifier along with the Solidity version, the
code was written for. In the snippet above, the Solidity code is for Solidity >=0.8.0 Then we
use the contract keyword to declare the contract, after which we name it VOHCoinERC20.

 After this step, we are going to declare the events Transfer and Approval inside our contract:

Transfer(address indexed from, address indexed to, uint tokens);


eventApproval(address indexed tokenOwner, address indexed spender, uint tokens);

Allocating the Name, Symbol, and Decimal for the Token

 After declaring the events, we now move on to allocating symbol, name, and, decimal for
the token:

string public constant name = "VOH Coin";

string public constant symbol = "VOHN";

uint8 public constant decimals = 18;

 In this case, our token name is VOH Coin and our symbol is VOHN. The decimals are set to be
18 respectively.

Declaring Mappings

 Now that we are done with the above steps, we move on to declaring the two mappings:

mapping(address => uint256) balances;

mapping(address => mapping (address => uint256)) allowed;

 In Solidity, a mapping is comparable to a key-value pair. In the balances, the key is an


address, and the value is an uint256 (unsigned integer of 256 bits).

 An address type, according to the Solidity documentation, is a 160-bit value that does not
support any arithmetic operations. It can be used to store contract addresses or a hash of
the public half of a key pair that belongs to external accounts.

 The balances maps an address to a uint256 int:

Address uint256

0x01 23

0x02 10

0x03 2

Defining the Total Quantity of Tokens Accessible

 The next line of code will be used to declare the number of tokens accessible in our contract,
which is as follows:

uint256 totalSupply_;

Defining the Value of Net Supply and Balances

 Now we have to deal with the constructor, which as of you know, is called at the time of
class creation. In the case of smart contracts, we call the constructor when the contract is
deployed to the desired network.

constructor(uint256 total) {
totalSupply_ = total;

balances[msg.sender] = totalSupply_;

 In the snippet above, we call the constructor with the total number of tokens we want to be
in our contract (total). The total is equal to totalSupply_, and the deploying address's
balance is equal to the total tokens. The Ethereum account of the currently executing
contract function is stored in the msg.sender variable.

Acquiring Owner Balance

 Now we are going to employ the balanceOf method:

functionbalanceOf(address tokenOwner)publicviewreturns(uint){

return balances[tokenOwner];

 tokenOwner is an argument to this procedure. This parameter is the token owner's address,
to whom we wish to refund the token's balance in the contract. As a result, the procedure
retrieves the balance by looking for the tokenOwner address in the balances.

Transferring Tokens to Desired Account

 We are going to work with the transfer method:

function transfer(address receiver, uint numTokens) public returns (bool) {

require(numTokens <= balances[msg.sender]);

balances[msg.sender] -= numTokens;

balances[receiver] += numTokens;

emit Transfer(msg.sender, receiver, numTokens);

return true;

This method consists of the following arguments:

 The account address that will get tokens which is receiver

 The quantity of tokens that will be sent to receiver account that is numTokens

 The method's body contains a check to ensure that the quantity of tokens to be given to the
receiver is sufficient based on the deployer's address balance.

 The numTokens are then deducted from the deployer's account and credited to the receiver
account. After that, a Transfer event is fired. Finally, true is returned as a Boolean value.
Sanctioning a Token Transfer

 Now we are going to use the approve method

functionapprove(address delegate, uint numTokens)publicreturns(bool){

allowed[msg.sender][delegate]= numTokens;

emit Approval(msg.sender, delegate, numTokens);

returntrue;

 The inputs to this procedure are delegate and numTokens.

 delegateis the address we want to set the number of tokens that the deployer can send to it

 numTokensis the number of tokens the deployer can send to the delegate

 To set the number of tokens, we reference the delegate map in the allowed mapping in the
method body. The Approval event is then emitted, and true is returned.

Acquiring the Allowance Status of Desired Account

 We proceed by using the allowance method:

functionallowance(address owner, address delegate)public view returns(uint){

return allowed[owner][delegate];

This method consists of the following arguments:

 owner and delegate. owner is the address to return the number of tokens transferable to
the recipient in the delegate.

Transferring Tokens from One Account to Another Account

We now write out our logic for the transfer mechanism as follows:

function transferFrom(address owner, address buyer, uint numTokens) public returns (bool) {

require(numTokens <= balances[owner]);

require(numTokens <= allowed[owner][msg.sender]);

balances[owner] -= numTokens;
allowed[owner][msg.sender] -= numTokens;

balances[buyer] += numTokens;

emit Transfer(owner, buyer, numTokens);

return true;

transferFrom has args called owner, buyerandnumTokens.

 The address of the balances from which the numTokenswill be transferred is owner, and the
address of the balances to which the numTokens will be credited is buyer. The number of
tokens to be transferred from the owner to the buyer is numTokens.

 We first verify whether the owner's balance is sufficient and whether the owner is
authorized to transmit that quantity of tokens to the buyer in the method body.

 After that, the transfer is made by removing the number of tokens from the owner's balance
and the authorized balance to complete the transfer. The buyer's balance is then increased
by the number of tokens purchased. The Transfer event is emitted, and the value returned is
true.

The final form of the contract should look like this:

Final Code

The complete code for the contract should look something like this:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.0;

contract VOHCoinERC20 {

event Transfer(address indexed from, address indexed to, uint tokens);

event Approval(address indexed tokenOwner, address indexed spender, uint tokens);

string public constant name = "VOH Coin";

string public constant symbol = "VOHN";

uint8 public constant decimals = 18;

mapping(address => uint256) balances;

mapping(address => mapping (address => uint256)) allowed;


uint256 totalSupply_;

constructor(uint256 total) {

totalSupply_ = total;

balances[msg.sender] = totalSupply_;

function totalSupply() public view returns (uint256) {

return totalSupply_;

function balanceOf(address tokenOwner) public view returns (uint) {

return balances[tokenOwner];

function transfer(address receiver, uint numTokens) public returns (bool) {

require(numTokens <= balances[msg.sender]);

balances[msg.sender] -= numTokens;

balances[receiver] += numTokens;

emit Transfer(msg.sender, receiver, numTokens);

return true;

function approve(address delegate, uint numTokens) public returns (bool) {

allowed[msg.sender][delegate] = numTokens;

emit Approval(msg.sender, delegate, numTokens);

return true;

}
function allowance(address owner, address delegate) public view returns (uint) {

return allowed[owner][delegate];

function transferFrom(address owner, address buyer, uint numTokens) public returns (bool) {

require(numTokens <= balances[owner]);

require(numTokens <= allowed[owner][msg.sender]);

balances[owner] -= numTokens;

allowed[owner][msg.sender] -= numTokens;

balances[buyer] += numTokens;

emit Transfer(owner, buyer, numTokens);

return true;

Hurray. Your very first ERC-20 token is now ready. You can play around with your contract by
deploying it on a local Virtual Machine through Remix (which we covered yesterday).

Final Thoughts

Today, we walked you through the process of creating your very own ERC-20 token in the Ethereum
network. Please note that this is a fungible token standard and we'll be covering the non-fungible
tokens (NFTs) later in this series. Fingers crossed and as always, Happy Coding!

You might also like