In this tutorial my objective is to walk you through the steps of setting up your account through to issuing your first token on the Ethereum network using a single smart contract and MyEtherWallet.
The token will be a standard ERC20, it will have the main functions and can be used as a general base for more sophisticated applications than just transferring them (many “half-serious” ICOs have extremely similar contracts)
Before we start:
There are a few different components you will need in order to build your own token.
Ethereum Address (Ropsten Network)
Some Ethereum (Ropsten Network)
A text editor (I.e. Sublime / Atom)
Solidity contract
Ethereum address
For this tutorial we will use a test network to issue the token so you don’t end up spending real Ether’s. We will use the Ropsten Test network. In order to get started, go to MyEtherWallet (MEW) and create an account there.
To get setup, click the right hand side corner, change the network to Ropsten (MyEtherWallet) → click the New Wallet →Enter a password you can remember → Download / Save your Keystore file in a safe space → Save your Private Key in a safe space.
To view your wallet address, go to →View Wallet Info →Private Key → Enter the saved private key →Unlock your Wallet and it should be there!
Text Editor
Download one of the following text editors:
Sublime Text
Atom
Contract
Download the smart contract that the legendary Ethereum unicorn rider, BokkyPooBah has helped us to make, by clicking here. ⬅️
You will be editing this code for your own token
Ropsten Ethers
We have created our own faucet where you can request Ropsten Ethereum! Just access https://faucet.bitfwd.xyz/ and put your ropsten address and our smart contract will send you some!
Now let’s get started:
Open the contract you downloaded in your Text Editor.
Go to Line 3–15 and look at the comment section. Although this is a comment section, this will help you down the track. For me, 0Fucks was my first one :). Basically you send 0Fucks to someone when you don’t care.
Change Line 4 to the title of your Smart Contract
Change Line 6 to the Ropsten Ethereum address you created in MyEtherWallet
Change Line 7’s Symbol to your respective coin name (Keep it short)
Change Line 8 to the name of your token
Next:
Go to Line 102 and change “FucksToken” to “(YourTokenName)
Do the same for Line 115
Go to Line 116 and change the symbol name, the same as the ones you did in the comment section
Do the same for Line 117
Change Line 120’s Address to be the same as the one you generated in MEW
Same goes for Line 121
For the decimals and total supply on Line 118 and 119, you can just leave it as it is however I’ll explain it just for visibility. On total supply there are actually a few considerations. First one is that the standard (and max) is 18 decimals, meaning that a coin can be splitted in 18 parts.
The second one is that let’s say for example you want to issue 100 tokens, on the total supply part you have to put 100 followed by the number of decimals that you choose.
Ex: If I want to emit 100 tokens, what I will put on total supply is: 100000000000000000000; and so it goes.
After that we are done with editing code. Yep, that was easyyyy. Now we are going to do some cool stuff…
Go to http://remix.ethereum.org/
In the browser/ballot.sol, paste the code you just edited! If something red comes up, there is something wrong in the code. If there is yellow warning it’s alright, let’s hope for the best.
Now Under Compile →Details →Choose the Token you are creating
Under ByteCode press the button to copy the ByteCode to your clipboard —( Into this section, what may appear are different things on the ByteCode. What you have to copy is the “object” ByteCode, adding a 0x in the beginning. So you will have 0xByteCode.)
Go to MEW where we will start to deploy the contract. Remember we want to be on the Ropsten Test Network so make sure the top right hand corner says
Navigate to the Contracts tab → Press Deploy Contract
Paste your ByteCode into the ByteCode box. Your gas limit should automatically update
Access your wallet by going into the Private Key → Enter your private key →Unlock your wallet
Now press Sign Transaction →Deploy Transaction
Click on the transaction tx or access https://ropsten.etherscan.io to check if the contract went through. If it didn’t, start again and try to figure it out what you got wrong. If it did, you are a basically Vitalik 2.0, be proud.
Now we are going to register this contract. To do that:
In the Overview Tab → Click on the Contract Address
Go to the Contract Code Tab → Click Verify and Publish
Now you have 5 things to do on this page.
Be sure that the contract address field corresponds to the contract address that you have just deployed. Remember contract address is different to the MEW address you created so make sure not to get them confused
The contract name has to match the one in the code, in my case is this: FucksToken. This was on Line 102 in your code
To check which version of the complier, go back to the remix page where you got the BYTECODE from and look at the URL, the complier version will be there. In most cases it should be: v0.4.19+commit.c4cbbb05.js , but you want to try updated ones if by any chance this doesn’t work.
On Optimisation, choose No (We haven’t enable it before).
On ENTER THE SOLIDITY CONTRACT CODE BELOW, copy the whole code from Remix, and paste in that area. NOT THE BYTECODE, but the code itself. Can also be copied from your text editor.
Now, leave the other fields in blank and click on Verify and Publish.
If a success page come along with green checkmarks and stuff, you did it!
To confirm that it works, go to https://ropsten.etherscan.io/ and look into your MEW Address, not the contract one, but your public address. If you can see your coins there, now you can relax and live the crypto dream in peace!
To be able to send these tokens, you need to access your MEW account by Viewing Wallet Info →Accessing and putting in your private Key →Unlocking Wallet →Select the option Load Tokens. After that they will show up to be transferable.
pragma solidity ^0.4.18;
// ----------------------------------------------------------------------------
// 'LOT' token contract
//
// Deployed to : 0x4200d1265f7772A52eD765734A08e1978454a266
// Symbol : LOT
// Name : Lottery Token
// Total supply: 100000000
// Decimals : 18
//
// Enjoy.
//
// (c) by Moritz Neto with BokkyPooBah / Bok Consulting Pty Ltd Au 2017. The MIT Licence.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// Contract function to receive approval and execute function in one call
//
// Borrowed from MiniMeToken
// ----------------------------------------------------------------------------
contract ApproveAndCallFallBack {
function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}
// ----------------------------------------------------------------------------
// Owned contract
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
function Owned() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and assisted
// token transfers
// ----------------------------------------------------------------------------
contract LotToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function LotToken() public {
symbol = "LOT";
name = "Lottery Token";
decimals = 18;
_totalSupply = 100000000000000000000000000;
balances[0x4200d1265f7772A52eD765734A08e1978454a266] = _totalSupply;
Transfer(address(0), 0x4200d1265f7772A52eD765734A08e1978454a266, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
}
official tutorial https://ethereum.org/token