0% found this document useful (0 votes)
134 views67 pages

How To Build Your Own Ethereum Based ERC20 Token and Launch An ICO in Next 20 Minutes - Hashnode

This document provides instructions for creating an Ethereum-based ERC20 token and launching an initial coin offering (ICO) in 20 minutes. It includes sample smart contract code to define the basic functions of a token like total supply, balance of addresses, and transferring tokens. The code provided implements the ERC20 token standard for compatibility with other Ethereum clients and wallets.

Uploaded by

Guillermo Vidal
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)
134 views67 pages

How To Build Your Own Ethereum Based ERC20 Token and Launch An ICO in Next 20 Minutes - Hashnode

This document provides instructions for creating an Ethereum-based ERC20 token and launching an initial coin offering (ICO) in 20 minutes. It includes sample smart contract code to define the basic functions of a token like total supply, balance of addresses, and transferring tokens. The code provided implements the ERC20 token standard for compatibility with other Ethereum clients and wallets.

Uploaded by

Guillermo Vidal
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/ 67

How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Start a personal dev blog on your domain for free with Hashnode
and grow your readership.

Get Started

How to build your own Ethereum based


ERC20 Token and launch an ICO in next
20 minutes

Sandeep Panda

Dec 18, 2017

1 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Update: I'm writing a book on Ethereum Smart Contracts. It's available


for purchase on LeanPub. If you are interested in learning more about
Smart Contracts and building Decentralized apps, feel free to give this
a try.

If you are looking for advanced stuff such as Presale, Public Sale,
Discounts, goal, hard cap etc.. check out my latest article.

Lately I have been digging into blockchain and decentralised apps to


educate myself and improve my knowledge. To make the learning
process fun I decided to build my own Ethereum based token and
understand the process of launching an ICO �Initial Coin Offering).

This article aims to give you an overview of how smart contracts work
in Ethereum by launching a simple demo ICO.

Make Hashnode your discussion hub for all things crypto. Check out
our crypto communities and join the blockchain-related discussions.

Basics

Here are a few basic terms we are going to use in this article. If you are
familiar with the following concepts, feel free to skip to the next
section.

Ethereum based ERC20 Tokens: In Ethereum tokens represent any


tradable goods such as coins, loyalty points etc. You can create
your own crypto-currencies based on Ethereum. Additionally the
benefit of following ERC20 standard is that your tokens will be
1
compatible with any other client or wallets that use the same

2 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

standards.

Smart Contracts: Smart Contracts are self executing code blocks


deployed on the Ethereum blockchain. They contain data & code
functions. Contracts make decisions, interact with other contracts,
store data and transfer Ether (the unit of crypto-currency in the
Ethereum blockchain) among users.

Solidity: A language for writing smart contracts.

MetaMask/Mist/MEW Wallet: A digital facility that holds your Ether


and other Ethereum based tokens.

Now that you are aware of the basic terminologies used in this article
let's get started.

Step 1� Code

Open your favourite text editor and paste the following code:

COPY

pragma solidity ^0.4.4;

contract Token {

/// @return total amount of tokens


function totalSupply() constant returns (uint256 supply) {}

/// @param _owner The address from which the balance will be retrieved
/// @return The balance
1
function balanceOf(address _owner) constant returns (uint256 balance)

3 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

/// @notice send `_value` token to `_to` from `msg.sender`


/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success)

/// @notice send `_value` token to `_to` from `_from` on the condition it i
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value)

/// @notice `msg.sender` approves `_addr` to spend `_value` tokens


/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success)

/// @param _owner The address of the account owning tokens


/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns

event Transfer(address indexed _from, address indexed _to, uint256 _value);


event Approval(address indexed _owner, address indexed _spender, uint256 _v

contract StandardToken is Token {

function transfer(address _to, uint256 _value) returns (bool success)


1
//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as tim

4 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

//Replace the if with this one instead.


//if (balances[msg.sender] >= _value && balances[_to] + _value > balanc
if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}

function transferFrom(address _from, address _to, uint256 _value)


//same as above. Replace this line with the following if you want to pr
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value &
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}

function balanceOf(address _owner) constant returns (uint256 balance)


return balances[_owner];
}

function approve(address _spender, uint256 _value) returns (bool success)


allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}

function allowance(address _owner, address _spender) constant 1 returns


return allowed[_owner][_spender];

5 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

mapping (address => uint256) balances;


mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}

contract HashnodeTestCoin is StandardToken { // CHANGE THIS. Update the contrac

/* Public variables of the token */

/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include
They allow one to customise the token contract & in no way influences the c
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be s
string public symbol; // An identifier: eg SBX, XPR etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (t
address public fundsWallet; // Where should the raised ETH go?

// This is a constructor function


// which means the following function name has to match the contract name d
function HashnodeTestCoin() {
balances[msg.sender] = 1000000000000000000000;
totalSupply = 1000000000000000000000;
name = "HashnodeTestCoin";
decimals = 18;
symbol = "HTCN";
1
unitsOneEthCanBuy = 10;
fundsWallet = msg.sender;

6 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

fundsWallet = msg.sender;
}

function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
require(balances[fundsWallet] >= amount);

balances[fundsWallet] = balances[fundsWallet] - amount;


balances[msg.sender] = balances[msg.sender] + amount;

Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to th

//Transfer ether to fundsWallet


fundsWallet.transfer(msg.value);
}

/* Approves and then calls the receiving contract */


function approveAndCall(address _spender, uint256 _value, bytes _extraData)
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);

//call the receiveApproval function on the contract you want to be noti


//receiveApproval(address _from, uint256 _value, address _tokenContract
//it is assumed that when does this that the call *should* succeed, oth
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,
return true;
}
}

Based on the original source from Token-Factory.

1
The above code uses Solidity language to build a simple ERC20 token.

7 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

The code is well commented and is very easy to understand. Once you
paste the code into your text editor, find the text: "CHANGE THIS". This
is what you need to change based on the characteristics of your token.
In the example above, I have named my token HashnodeTestCoin
�HTCN�. The total supply is capped at 1000, but people can possess as
little as 0.000000000000000001 because of 18 decimal places.
Additionally, the owner of the contract (one who executes it) gets all
the initial tokens. I have set the ICO price as following:

1 ETH � 10 HTCN

This means, if someone sends 1 ETH to this smart contract, they will
get 10 HTCN units.

Step 2

Download MetaMask chrome extension to generate a wallet. This is


going to be the owner of the smart contract. Alternatively you can
always use Mist or My Ether Wallet. For the sake of simplicity let's use
MetaMask extension in this project.

Once you download the extension, go ahead and create a new account
protected by a password. Then choose "Ropsten TestNet" from the top
left corner. Before we deploy the contract to Main Ethereum
blockchain, we'll test it against TestNet and make sure everything
works as expected. It looks something like this:

8 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Now head over to Remix IDE (an online solidity compiler and debugger)
and paste the code you just modified. Ignore any warnings you see.
Next go to settings and uncheck "Enable Optimizations" if it's checked.

Now go to "Run" tab and click on create under <your token name>.

1
Once you hit create, MetaMask will prompt you to buy some test ether

9 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

and submit the transaction. It looks something like this:

Just make sure you are on Ropsten TestNet and not on the MainNet 1

and then hit Submit. Now open up MetaMask again and click on the

10 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

and then hit Submit. Now open up MetaMask again and click on the
first transaction. It'll take you to Etherscan where you can observe the
ongoing transaction. It may take up to 30s to confirm the transaction.
Once it's confirmed it looks like the following:

Viola!! You just deployed your contract. Note the to address in the
above transaction page. That's your contract address.

Now it's time to verify if it actually works.

Step 3

Ideally if you've set up everything correctly you should receive all the
initial tokens �1000 in my case) when you add it to your wallet. So, copy
the contract address, go to MetaMask � Add Token and paste the
address. It looks like the following: 1

11 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Hit Add and refresh MetaMask. You should now see all the initial supply
(in my case it was 1000 HTCN�. :)

Step 4

Now that everything works perfectly we just have to verify our smart
contract so that everyone on the blockchain can read and understand
it. It's always a good practice to verify since it helps establish trust.

Now go to your contract address and click on Contract Code tab.

12 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Now click on "verify and publish" link. Once you are taken to the new
page, fill up the details such as compiler version, Enable Optimizations
etc and paste the solidity source we compiled in the first step.

Make sure the compiler version you choose matches the one you
compiled your code against in the first step. Now hit "verify and
1
publish". If successful, it'll generate bytecode and ABI as following:

13 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Congrats! Now anyone can visit your contract address and read the
source.

Step 5

To deploy your contract to production, you just need to switch TestNet


to MainNet on MetaMask (located at top left corner) and repeat step 2
to 4. Please be aware that you will have to spend real Ether over there
to deploy your contract. So, don't deploy the contract unless you are
fully ready �Contracts are immutable and can't be updated once
deployed). We'll keep using TestNet in this tutorial.

Buying tokens with Ether 1

14 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

As a part of the ICO, your users will buy tokens from you by paying
ETH. Remember we set the price as 1 ETH � 10 HTCN while deploying
the contract? So, if a user wants to buy 10 HTCNs through your ICO,
they have to pay 1 ETH. Let's test this out.

Go to MetaMask, create a new account and load it with some Test


Ether. Once the account is loaded, click "Send" and fill up your contract
address. In the amount field, enter 2 �ETH�.

Next, send 2 ETH to the contract address and wait for the transaction
to be confirmed. Refresh MetaMask and check your tokens after a few
seconds. The new test account should have got 20 HTCNs (or
something different depending on your config) and the contract owner
(you) should have 980 (or something similar) tokens.

15 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Additionally, you should have received 2 ETH.

Congrats on the success!

Launching an ICO page

To display the amount of ETH raised by our project, we'll use a


JavaScript library called Web3.js on our website.

Head over to Hashnode Test Coin ICO and check out the code in the
last <script> tag. It's fairly simple and just uses Web3.js and ABI
obtained from your contract.

16 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Congrats if you have made this far! Do keep in mind that real
production grade contracts and ICOs take significant efforts and are
supported by thorough tests. While this tutorial gives you an overview
of writing contracts for ICOs, it's never meant for production level
deployment. Don't deploy this on MainNet without proper testing!

Thanks for reading this article. If you have any questions, please feel
free to comment below.

Have blockchain-related questions? Check out these crypto


communities on Hashnode and start a discussion.

37

17 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

READ NEXT �

Sandeep Panda

Hashnode's Annual Tech Awards 2021


As we come to the end of the year, I want to say a big THANK YOU � to our community
for helping tho…

Sandeep Panda

18 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

How we autodetect spam using Google's Vertex AI


One of the downsides of our recent growth was an increase in spam. Since we all hate
spam, and it wa…

Sandeep Panda

Winners of July Giveaway!


Hey everyone! Last month we ran the 5th edition of our coffee giveaway. We're super
excited to anno…

19 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Comments �102�

Top First Write a comment

Sai Kishore Komanduri


Engineering an eGovernance Product | Hashnode Alumnus | I love pixel art

Dec 19, 2017

I'll invest in this ICO! � Go HTCN!

Reply 3

Anwar Shaikh Mar 2, 2018

Hey Sundeep, Not able to buy your book mentioned above as it


says payment declined. I am preety sure I have money in my
account. Also the web3.js is not displaying the ethers earned. Can
you please have a tutorial on web3.js to learn the front end as well.

Like

Reply

Ukognes Dec 23, 2017

Thank so much for this great write up. 1

20 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

I have a question regarding the web3.js ico announcement page.

It seems that the js only runs if you have metamask installed on


the browser.

Is there a way to display the "total raised" for all visitors


regardless of which extensions they have running?

Perhaps I need to understand it better. Is there a write up


anywhere you'd recommend?

Thanks!

Reply 3

Sandeep Panda Jan 22, 2018

Sorry about the late response. You can try Ethers-js and fetch the
balance. In fact, I should have used that in the article instead of
relying on web3. Thanks for pointing out.

Like

Reply

Sebastian Jan 15, 2018

Great job! I have a problem however:


1

I have set that unitsOneEthCanBuy � 1000;

21 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

I have set that unitsOneEthCanBuy � 1000;

In MetaMask �Eth net): when I send 1 ETH I got 10.000 of mycoin..


when I send 0.001 ETH I got 0.010 � why is that?

In MyEtherWallet: when I send 0.001 ETH I got 0.1 mycoin...

Why there are differences? Morover, when I deploy the SAME


contract in test net, and test it, it works properly... There are no
differences in codes, only difference is that one is on real eth net,
and the other in test net.

Reply 3

Show �6 replies

Kallejo Feb 21, 2018

I have the same problem, all ok but if i send 0.05 eth yo contract,
this contract dont send me mys tokens... Any solution?

Like

Reply

AYOOLA OKUNSANYA Oct 5, 2019

Great ....you WhatsApp contact please....I would need your


expertise and consults on my community blockchain deployment
project on er20 sir.... �2347086967090 Thanks.

Like

Reply
1

22 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

rendy setyawan �The Rens) Jan 7, 2018

Why I get error like this :

"creation of RENToken errored: Gas required exceeds block gas


limit: 30000000. An important gas estimation might also be the
sign of a problem in the contract code. Please check loops and
be sure you did not sent value to a non payable function (that's
also the reason of strong gas estimation). "

whats wrong ? I follow all tutorial but I get thats :(

Reply 2

Matt Jan 31, 2018

Make sure the value of the coin is 0 in the run tab of the Remix IDE.

Like

Reply

Wei Huang Feb 21, 2018

hi. Great article. I have question. On your final ICO webpage, there
is starting and ending date, plus bonus for the first week buyer, do
you have code example for that? Great thanks!

Like 1

Reply

23 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Gautam Lakum
Intrapreneur. Project Coordinator in the mobile apps development agency. Love …

Dec 18, 2017

Thanks Sandeep Panda for posting this. It seems a long article,


could't read fully. I will surely go through it.

Reply 1

Eshwaran Veerabahu Dec 19, 2017

Not able to switch to Ropsten TestNet on the meta mask prompt.

Like

Reply

Liviu Craciun Feb 9, 2018

Great tutorial, thank you very much, I was able to deploy my first
ERC20 yey! Would you also do a tutorial on how to build ERC23
Tokens? Apparently they are the next evolutional step in this
technology. Best!
1

Reply 1

24 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply

Super Ted Jan 26, 2018

Are you able to delete these test coins? If so how?

Reply 1

Jimi S Feb 11, 2018


w/e

Awesome read so far! I have a question though: my current code


does not want to distribute any of the tokens in response to Ether
transactions. I've sent a few Ether from various test accounts to
the contract, but the contract won't send any of the tokens back.
What am I doing wrong? My code:

Edit: The Ether also seems to be stuck at the contract address


and is not being send to the address that has created the
contract.

pragma solidity ^0.4.4;

contract Token {
1

function totalSupply() constant returns (uint256 supply) {}

25 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

function balanceOf(address _owner) constant returns (uint256 balance)


function transfer(address _to, uint256 _value) returns (bool success)
event Transfer(address indexed _from, address indexed _to, uint256 _value);
}

contract StandardToken is Token {

function transfer(address _to, uint256 _value) returns (bool success)


if (balances[msg.sender] >= _value && _value > 0) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}

function balanceOf(address _owner) constant returns (uint256 balance)


return balances[_owner];
}

mapping (address => uint256) balances;


mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
}

contract JIMI is StandardToken { // CHANGE THIS. Update the contract name.

/* Public variables of the token */

/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include
They allow one to customise the token contract & in no way influences the co
1
Some wallets/interfaces might not even bother to look at this information.

26 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

*/
string public name = 'JIMI'; // Token Name
uint8 public decimals = 0; // How many decimals to show. To b
string public symbol = 'JIMI'; // An identifier: eg SBX, XPR
string public version = 'J1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (th
address fundsWallet = 0xb6F6d01aAf700C83819cE0707C6B69607AfF36a9

// This is a constructor function


// which means the following function name has to match the contract name de
function JIMI() {
balances[msg.sender] = 1000; // Give the creator all initi
totalSupply = 1000; // Update total supply (1000
name = "JIMI"; // Set the name for dis
decimals = 0;
symbol = "JIMI";
unitsOneEthCanBuy = 100;
fundsWallet = msg.sender;
}

function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
if (balances[fundsWallet] < amount) {
return;
}

balances[fundsWallet] = balances[fundsWallet] - amount;


balances[msg.sender] = balances[msg.sender] + amount;

Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the

1
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);

27 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

fundsWallet.transfer(msg.value);
}

Reply 1

Just Modifci Feb 17, 2018

Same here

Reply

Romain NEUVILLE Jun 19, 2018

Same

Like

Reply

Ju Chun Ko Feb 18, 2018

Really love this tutorial, it's clear and beautiful. Already bought
the book. Please do keep writing. We need more people to
understand Solidity. Once you've done, I hope I can translate your
book to Chinese and bring it to Chinese language world. :)) 1

28 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply 1

Sandeep Panda Feb 19, 2018

Thanks! Glad you found the article useful. :)

Reply

John Bartholomew Feb 6, 2018

Stuck on step 3. My token that i just created showed up as


initially 0. I did step 1 and 2 correctly.

Help is appreciated.

Reply 1

Pedro Febrero Jan 23, 2018

Thank you so much for this awesome article (and explanation). If


you use steemit, share it below!

Quick question: what if you create 100 tokens, but you only want 1

to give 50% away in the ico, how could you do it? I mean you

29 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

could obviously create 50 tokens and then mint more (i guess?�,


but is there a function for that?

Thank you!

Reply 1

Sandeep Panda Jan 23, 2018

Thanks for the nice words! I would go with MintableTokens. I just


wrote an article that addresses exactly this. �� Let me know what
you think.

Like

Reply

Felipe Bueno Feb 1, 2018

Hello, could you help me? I was able to create the contract but
when I send ETH to the contract address, I do not receive
MYCOIN. I compared the contract I created with the contract
published by the article, and it's the same. What can it be?

Reply 1

Sandeep Panda Feb 5, 2018


1

Hey there! Did you Add the specific token to MetaMask? By default

30 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Hey there! Did you Add the specific token to MetaMask? By default
it doesn't show all the available tokens.

Like

Reply

Kyra .O. Taylor Feb 22, 2018

Sandeep please help, the contract is not sending token when eth is
sent to it.

Reply

Faizal SB Jan 28, 2018

Hello, I didnt see where to put cap limit token user can buy..
Where is it?

For example Total supply 21mil. People can only buy 10mil of
it..Where to put that 10mil? 1

31 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply 1

Sandeep Panda Feb 5, 2018

Check out my new article that addresses this.

Like

Reply

Thanh Le Feb 10, 2018

I'm having a strange issue, when I send Ether into the contract
address nothing happens, the contract just holds the Ether and
does not send my token out.

Reply 1

Jimi S Feb 12, 2018

Same problem.

Like

Reply

Kyra .O. Taylor Feb 18, 2018

1
same problem.

32 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply

John Verma Feb 20, 2018

Where should i put the owner (my) erc20wallet to recieve


creators tokens.and should i put directly or in between ().Please
say me where to put my address.

Reply 1

Shanti Bodhinanda Jun 15, 2018


Founder Online LIFE World

My token holder address after running:


0�0000000000000000000000000000000000000000

how to fix it?

Reply 1

Romain NEUVILLE Jun 19, 2018

Same 1

33 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Like

Reply

Gooz Albright (goozerin) Jun 7, 2018

is it possible, after creating the coin to create more coins with


same contract address?

Reply 1

howekuo Mar 5, 2019

Try this dAPP, tokenmaker.app, Easy and fast to create the


ERC20 or ERC223 token without any coding

Reply 1

Ronon margo Mar 18, 2020


Digital Marketing Executive

Sounds good. Here I would like to suggest one more article which 1

is very helpful for create my own ethereum based ERC20.

34 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

is very helpful for create my own ethereum based ERC20.

Reply 1

scarlet emilye Dec 26, 2018


Marketing Manager

Hey great article.

In ethereum blockchain, the ERC20 tokens are created using the


agreement called smart contracts. The algorithm used for the
creation is ERC20. The smart contracts are nothing but the
execution code built on the ethereum functions and they are
written using the language called solidity. Ethereum and ETH
tokens are stored on the digital storage space called Meta Mask.
This is what the people know about erc20 tokens. In my opinion,
instead of learning and creating erc20 tokens, you can contact
the erc20 token development company @
https://www.cryptoexchangescript.com/erc20-token-
development . Hope this helps

Reply Like

Nigel Bloom Jan 16, 2019

1
That is true � STOs are the ICOs of the next generation. More

35 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

secured. And by the way if you are the one who is planning to
launch your own ICO/STO � i strongly recommend flexe.io/413
These guys were really good and DO understand how fund
raising works.

Reply Like

Olga Miller Dec 12, 2018


entrepreneur

It’s good that technology is developing fast. Already now you can
create your Ethereum token and run own ICO with just a few
clicks immediately without using code at all. Go to the link
mywish.io

Reply Like

Kenon Mar 13, 2019


Student

So the ICO created depends on the price of Ethereum?

Reply Like

36 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Shrinivas mani Mar 11, 2019


Dev

hi

Any provide wallet development concept please provide you tube


link and script

Reply Like

Keith Mar 21, 2019


Script kid

everything is now different, some of the buttons you mentioned


are not even there on the new .SOL editor, pls update this post, i
followed every step closely.

Reply Like

Аnna Apr 12, 2019

I am a beginner, and for the first time tried to trade on the


exchange. A friend who has been doing this for a long time
advised to trade Freldo Token, since this token is quite stable and 1

reliable. It's simple and easy. I will leave a link for those who want

37 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

reliable. It's simple and easy. I will leave a link for those who want
to try it too bcex.hk/trade/frecnx_eth

Reply Like

Orlan Silva May 24, 2019


Legal Advisor

How about starting your own campaign at mintme.com and grant


those who believe in you a reward? Blockchain can be also a
perspective, a way to see things. Through such a technology
almost anything can be tokenized and, whatever it can be so, it
will eventually become in a mean of exchange, a new kind of
money, with no government imposition; regulation perhaps, but
open minded at the end.

Reply Like

Hash Sep 26, 2019

I am having the following issue: When


i send ETH to the contract i receive
"Failed To Send" on the metamask
wallet, and the warning on Remix is: 1

38 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Fallback function of contract requires


too much gas (infinite). If the fallback
function requires more than 2300
gas, the contract cannot receive
Ether.

I tried to find some tutorials to fix it but i did not was enable to
find something useful and that i can understand.

This is how the code i am using is:

pragma solidity ^0.4.24;

library SafeMath { /**

* @dev Returns the addition of two unsigned integers, reverting on


* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");

return c;
}
1

/**

39 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256)
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;

return c;
}

/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256)
// Gas optimization: this is cheaper than requiring 'a' not being zero,
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}

uint256 c = a * b; 1

require(c / a == b, "SafeMath: multiplication overflow");

40 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

return c;
}

/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256)
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't

return c;
}

/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned i
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements: 1
* - The divisor cannot be zero.

41 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

*/
function mod(uint256 a, uint256 b) internal pure returns (uint256)
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}

contract Token {

/* This is a slight change to the ERC20 base standard.


function totalSupply() constant returns (uint256 supply);
is replaced with:
uint256 public totalSupply;
This automatically creates a getter function for the totalSupply.
This is moved to the base contract since public getter functions are not
currently recognised as an implementation of the matching abstract
function by the compiler.
*/
/// total amount of tokens
uint256 public totalSupply;

/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) public view returns (uint256 balance)

/// @notice send `_value` token to `_to` from `msg.sender`


/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) public returns
1

/// @notice send `_value` token to `_to` from `_from` on the condition it is

42 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

/// @param _from The address of the sender


/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value)

/// @notice `msg.sender` approves `_spender` to spend `_value` tokens


/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of tokens to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) public returns

/// @param _owner The address of the account owning tokens


/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) public view

// solhint-disable-next-line no-simple-event-func-name
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _va

contract StandardToken is Token {

function transfer(address _to, uint256 _value) returns (bool success)


//Default assumes totalSupply can't be over max (2^256 - 1).
//If your token leaves out totalSupply and can issue more tokens as time
//Replace the if with this one instead.
//if (balances[msg.sender] >= _value && balances[_to] + _value > balance
if (balances[msg.sender] >= _value && _value > 0) {
1
balances[msg.sender] -= _value;
balances[_to] += _value;

43 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}

function transferFrom(address _from, address _to, uint256 _value)


//same as above. Replace this line with the following if you want to pro
//if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value &&
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}

function balanceOf(address _owner) constant returns (uint256 balance)


return balances[_owner];
}

function approve(address _spender, uint256 _value) returns (bool success)


allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}

function allowance(address _owner, address _spender) constant


return allowed[_owner][_spender];
}

mapping (address => uint256) balances;


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

uint256 public totalSupply;

44 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

contract MyToken is StandardToken { using SafeMath for uint256;

uint256 constant private MAX_UINT256 = 2**256 - 1;


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

string public name; // Token Name


uint8 public decimals; // How many decimals to show. To be st
string public symbol; // An identifier: eg SBX, XPR etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (th
address public fundsWallet; // Where should the raised ETH go?

// This is a constructor function


// which means the following function name has to match the contract name de

function MyToken() {
balances[msg.sender] = 1000000000000000; // Give the creat
totalSupply = 1000000000000000 ; // Update total
name = "MyToken"; // Set the name for
decimals = 8;
symbol = "MYT";
unitsOneEthCanBuy = 1000;
fundsWallet = msg.sender;
}
1

function() payable{

45 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
require(balances[fundsWallet] >= amount);

balances[fundsWallet] = balances[fundsWallet] - amount;


balances[msg.sender] = balances[msg.sender] + amount;

Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the

//Transfer ether to fundsWallet


fundsWallet.transfer(msg.value);
}

/* Approves and then calls the receiving contract */


function approveAndCall(address _spender, uint256 _value, bytes _extraData)
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);

require (!_spender.call(bytes4(bytes32(keccak256("receiveApproval(addres
return true;
}

function transfer(address _to, uint256 _value) public returns


require(balances[msg.sender] >= _value);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, n
return true;
}

function transferFrom(address _from, address _to, uint256 _value)


uint256 allowance = allowed[_from][msg.sender]; 1

require(balances[_from] >= _value && allowance >= _value);

46 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT256) {
allowed[_from][msg.sender] -= _value;
}
emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unu
return true;
}

function balanceOf(address _owner) public view returns (uint256 balance)


return balances[_owner];
}

function approve(address _spender, uint256 _value) public returns


allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value); //solhint-disable-line inde
return true;
}

function allowance(address _owner, address _spender) public view


return allowed[_owner][_spender];
}

Thank you for your attention,

Reply Like

rangler amartya Jun 7, 2020

47 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

rangler amartya Jun 7, 2020

so what is the difference between this and the tokens you can
create on Mintme ?

Reply Like

Bhanu Teja Mar 19, 2018

Please send me some small ethereum I have 0 eth I couldn’t even


exchange my tokens please some one send me to
0xbCC35393C3456e4000C0761FB0970548cEBA4013 I promise
you to return back

Reply Like

André Furtado Apr 22, 2018

Is it possible to add a text data with a token transfer? I could only


add text with a ropsten eth transaction send.

Reply Like

48 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Michael May 20, 2018


Curious Teenager

So how would you start sending tokens from one account to the
other?

Reply Like

Naveen Feb 15, 2018

Hello Sandeep, this is a great Write up. We are trying to generate


a smart contract with ERC20. My question is � Can we follow the
above process on MAC OS too ?

Reply Like

Sandeep Panda Feb 15, 2018

Yes absolutely. I did the above using a Macbook. :)

Like

Reply

Naveen Feb 16, 2018

Thanks a lot Sandeep. Much Appreciate.

Like 1

Reply

49 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply

Roland Hrubaru Mar 11, 2018

Sadly I cand view the total ETH raised...any help is appreciated!

Reply Like

Morne du Toit Feb 24, 2018

Really amazing info, thank you! How do you add an image to the
coin / token?

Reply Like

Muhammad Shahzad Apr 13, 2018


CEO

I got this issue when compiling here:

remix.ethereum.org/#optimize=false&vers..
1

browser/ballot.sol:120�9� Error: Undeclared identifier.

50 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

require(balances[fundsWallet] >= amount); ^-----^

Reply Like

William Lim Jan 23, 2018

Hi! Just wondering - given there's a way to exchange 1 ETH for


xxx coin, what happens if someone sends 0.5 ETH ? would it
automatically send half of xxx coin?

Reply Like

Show �1 replies

William Lim Jan 23, 2018

Woohoo - tried to create a test coin and it worked. But


unfortunately, sending 1 ETH didn't work when testing with two
accounts. (ie: to test autosend token when receiving 1 ETH� Not
sure what's wrong with it... any ideas? source code exactly the
same except for # of tokens, names, decimal and put in a note.

Note: I sent 1 ETH from "my account 2" to Contract address - didn't
work (as specified in tutorial)

I sent 1 ETH from "my account 2" to "My Account 1" - didn't work

rinkeby.etherscan.io/token/0xc705e325395b7c..

Tested manually with just sending it using myetherwallet and it 1

works well.

51 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Like

Reply

Jimi S Feb 12, 2018

I have the same problem. Manually through MEW works you say?
How does that work? Access MEW with a test net and then send
through MEW instead of Metamask?

Like

Reply

This IsIt Feb 20, 2018


This Is It

Hi Sandeep,

How do we stop receiving eth after selling the amount of tokens


which needs to be sold ? Like I ve 1bn tokens but I want to sell
just 50% in an ICO. On selling 500m tokens, the contract should
stop receiving eth and stop deducting the tokens from the
contract. And how to unlock the tokens for a specific date and
time

Reply Like

52 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Roland Hrubaru Mar 9, 2018

Thank you for the great post! I have copied the code but I simply
cant click on create because the <your token name> tab is red
and I cant modify it. Please help thank you!

Reply Like

Tiwalayo Olarewaju Feb 16, 2018

Thanks for the write up. I followed the steps but for some reason,
at step 3 i don't receive my tokens. Please help!

Reply Like

Vivek Sharma Jan 25, 2018

Hello Sandeep,

I am beginner and working on ICO creation I have a question i


want to know How i can display the state of the ICO contract in
real time, i.e. Ethers raised, tokens sold and the remaining
1
duration of the ICO. or using web3js what are the function we can
use.

53 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

use.

Reply Like

DeezNuts �DEEZ� Feb 2, 2018


We hope DeezNuts put a smile on your face! ;) https://deeznuts.in

I would love to donate a portion of the tokens I have built with


your guidance among others. Is there an ERC20 compatible
address you are able to share where I can drop some of my
tokens on you? ;)

Reply Like

John Verma Feb 21, 2018

There are 2 problems Here � 1.When Eth is sent to the contract


address,upon sucessfull Conformation of TXN ,Tokens are Not
being sent to the Address From which User Sent Eth. 2.The Eth
that is sent by any user,The eth is not Being Sent to the Owner
Address i.e.,Contract Created by(Owner Address).And there is no
aceess to the eth of contract address(Token Address). So How
can i get the Eth? Please Give a Solution. Thankyou

Reply Like 1

54 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Steven Emerson Feb 26, 2018

This code does not work, don't use it

Reply Like

bitcamp supertiga May 4, 2018


CEO Digital Market Indonesia

how to make token can give passive income with staking?

Reply Like

Michael May 7, 2018


Curious Teenager

Hey!

1. how does

if (balances[msg.sender] >= _value && balances[_to] + _value > balances[


1

55 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

practically differ from

if (balances[msg.sender] >= _value && _value > 0) {

(both in function transfer)??

Reply Like

dardar Jan 8, 2018

I cant retrieve total raised, its blank..any help?

Reply Like

Heath Guido Jan 17, 2018

Mine says URI is too long when I run it in remix. What does that
mean? Thanks

Reply Like

Sxx Nxx Jan 23, 2018

56 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Sxx Nxx Jan 23, 2018

I m new to it. I m trying to create one directly thru MEW �


Contracts

I got following error. (no metamask, trying with private key


directly)

(error_10� Please enter a valid data value �Must be hex.)

Reply Like

Ilya Matv Feb 27, 2018

could anyone point me in the direction to read how transaction


made with HTGN is going to be paid on ethereum network? who
actually pays gas once 1HTGN gets passed from one wallet to
another?

Reply Like

Jason Mar 13, 2018

Thanks for this wonderful article! I was able to get my token up


and running on the test network. I did run into one issue though. 1

When the contract was nearly out of tokens to distribute, I sent a

57 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

large amount of ETH to the contract from my second account.


The ETH disappeared, and none of the tokens were received by
the sender. This was the point of my test, to see what would
happen when the contract ran out of tokens to distribute. Any
guidance on how to prevent someone from sending too much
ETH to the contract, or send the remaining tokens to the sender,
and refund the excess ETH? Thanks!

Reply Like

Sandeep Panda Mar 14, 2018

Hi Jason

Thanks for reporting this. We just need to change the following line
in payable function:

if (balances[fundsWallet] < amount) {


return;
}

to

require(balances[fundsWallet] >= amount);

I have updated the code samples above. This will ensure that if
there are not sufficient tokens, the ETH will be refunded.

Like

Reply

Jason Mar 26, 2018

58 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Jason Mar 26, 2018

Thanks for following up so quickly, I will continue to test!

Like

Reply

dardar Jan 8, 2018

i cant see the total raised, can you help?

Reply Like

Inayat Patel Apr 17, 2018


Joziz Tech

Awesome .. It will Be more Interesting. If you add Some Discount


& presale Codes

Regards

Reply Like

59 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Kristina Gwynne Jan 7, 2018

Hey Sandeep, thanks for this tutorial! I got stuck just before Step
3. I don't get taken to the Etherscan, I just keep getting a
MetaMask ether faucet page which is confusing me. I'm not sure
which key is mine for my new token. However, I managed to
create two tokens but neither of them are showing the name I
wanted or have provided me with the amount of tokens I set up in
my wallet. Not sure what I've done wrong. :(

Reply Like

Wendy Feb 5, 2018

What happen when there are no tokens to be sent when ether is


recieved ? "the contract ceases " ?

https://ethereum.stackexchange.com/questions/37469/how-to-
add-a-function-in-contract

unitsOneEthCanBuy = 10;
fundsWallet = msg.sender;
}

function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
1
if (balances[fundsWallet] < amount) {
return;

60 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

return;
}

balances[fundsWallet] = balances[fundsWallet] - amount;


balances[msg.sender] = balances[msg.sender] + amount;

Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to

Reply Like

Mohamed Safouan Besrour Jan 6, 2018

How to access funds that are sent to the smart contract address
?

Reply Like

Saúl Armenta Jan 11, 2018

You need access to that ETH address

Like

Reply

Sandeep Panda Jan 22, 2018

Funds sent to the smart contract are immediately transferred to the


owner of the contract. Owner is the wallet that deploys the
1
contract on the blockchain.

61 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Like

Reply

Sr. V K Mar 1, 2018


to the moon

Great article, please help me to get Message signature hash to


verify token contract

Reply Like

Igor Yalovoy May 24, 2018

ERC20 explicitly says:

“Note Transfers of 0 values MUST be treated as normal


transfers and fire the Transfer event.”

Yet, your code return false on 0 and do not call Transfer event.

if (balances[_from] >= _value && allowed[_from][msg.sender] >=

1
I guess, it is not fully ERC20 compatible then.

62 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply Like

Almasani Sep 11, 2018


CEO

This is my smart trial contract. ropsten.etherscan.io/address


/0xfe24233b7944..

Reply Like

Igor Yalovoy May 24, 2018

Amazing article. It might be a good idea to specify visibility


modifier for functions explicitly.

Reply Like

Maninder Kaur Jun 11, 2018


UI/UX, Web Design, Interaction Design at Alphonic Network Solutions

This is very helpful. Thanks for sharing it. 1

Like

63 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply Like

Pieter-Jan Snijders Aug 2, 2018


Data Scientist

Hi Sandeep,

Thanks for the extensive tutorial.

The contract works and my coin is put into my MetaMask Wallet.


However, the ICO part is not working when people send ETH to
the contract address. Could this be because I am on the Ropsten
Test Network? Or might it be because the contract is not
validated by EtherScan?

I hope you can help :)

Reply Like

Jason Don Jul 5, 2018

thanks for the wonderful article and explanation! What do you


think about ethermium.com? All the transactions are governed by
smart contracts that work in a preprogrammed fashion and are
designed to keep your funds safe. 1

64 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

Reply Like

Romain NEUVILLE Jun 19, 2018

Thanks for the article good tools to know and process for testing.
But as some says here, it seem there is a problem with the code.
Tokens are not created at step 3 and the wallet stay to 0 tokens
so the part 5 dont work too. It will very cool to fix this (and to
know why this dont work).

Reply Like

Almasani Sep 11, 2018


CEO

Sir, why is the total supply of tokens zero? Is the supply not
directly listed on a smart contract? Please help me.

Reply Like

Binish Paudel Sep 17, 2018


1
Software Engeneer

65 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

how to make , if someone sends 0 eth send them 100 token, not
if they send 1 eth send them 100

Reply Like

Jun Lester Castro Jun 21, 2018

Hi, why do i get this error, when i'm sending ether/s to contract
address

Reply Like

Diana Dubrovskaya Nov 14, 2018 1

66 de 67 11/03/2022 11:26 a. m.
How to build your own Ethereum based ERC20 Token and launch an IC... https://hashnode.com/post/how-to-build-your-own-ethereum-based-erc20...

thanks for the wonderful article and explanation. What do you


think about ethermium.com? All the transactions are governed by
smart contracts that work in a preprogrammed fashion and are
designed to keep your funds safe. I'm just a beginner in the
crypto world and I would like to know your opinion.

Reply Like

67 de 67 11/03/2022 11:26 a. m.

You might also like