Ever wanted to create a token for your project, build up a community of supporters by destributing tokens through an airdrop and maybe launch an ICO at some point? Then this guide is for you!
In this step-by-step guide we will show you how you can create your own ERC20 token and start distributing it through einax.com token trading platform.
0. Have some ETHIn order to finish this guide you will need to have at least $2 worth of Ethereum [ETH]. In this guide I'm using Metamask Chrome Extenstion which you can get here:
https://metamask.io/1. Creating an ERC20 Ethereum based tokenFirst we want to deploy a smart contract that is ERC20 standard compliant.
Open up
Remix (which is an awesome browser-based IDE for smart contract development) by following this link:
https://remix.ethereum.org/. By default you will see some ballot.sol smart contract. You may close this ballot.sol tab and create a new one by clicking on a circled "+" sign
Now once you've got a new empty tab copy the code below and paste it into Remix:
pragma solidity ^0.4.24;
// ----------------------------------------------------------------------------
// (c) BokkyPooBah / Bok Consulting Pty Ltd 2018. The MIT Licence.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal 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.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);
constructor() 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);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and a
// fixed supply
// ----------------------------------------------------------------------------
contract FixedSupplyToken is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "FIXED";
name = "Example Fixed Supply Token";
decimals = 18;
_totalSupply = 1000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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;
emit 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] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view 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;
emit 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);
}
}
I copied this code from
this wiki pageNow click "Start to comile" and make sure there are no compilation errors (red messages)
Now log in to your MetaMask browswer extension and make sure Remix is connected to it. It should appear like so:
Change your token name, symbol and total supply:
Now simply switch contract to FixedSupplyToken and hit Deploy button. That's it!
After you hit Deploy button Remix will ask you for a confirmation
If you're fine with the gas price it suggests you to pay you may click "Confirm" at the bottom of this pop up window.
This will bring up Metamask window that looks something like this:
Where we can see that our contract depoloyment will cost us $1.12
Now click "Confirm" button and your contract should be deployed to Ethereum mainnet
After a couple of minutes it should get confirmed and you will see the link to your freshly deployed smart contract in Metamask transactions list. Here's my token's deployment transaction:
https://etherscan.io/tx/0x6a39c40cc35eb03874808358eb0ab2ea9967c0c27f40fe3bf65c345fa2080da2Token's smart contract address is:
0x0e0a6c613ea16ae347cb98732e152530ae9bc7f2Great! At this point our token is fully functional.
2. Confirm contract on etherscan.ioIt's always a good idea to confirm your smart contracts code on etherscan.io so everybody will be able to view it easily. Since my token's contract address is 0x0e0a6c613Ea16aE347CB98732e152530Ae9Bc7F2 I will use it as an example
Go to token's contract page on etherscan.io:
https://etherscan.io/address/0x0e0a6c613ea16ae347cb98732e152530ae9bc7f2Click on
Code tab and hit
Verify And PublishOn the "Verify Contract Code" you should fill all the required fields correctly so etherscan could verify your token's smart contract code:
Click Verify and Publish button and if everything is well you should see the following:
Now that token's code is verified anybody can easily review it and make sure it does exactly what you are claiming it does. Furthermore this token is now eligible to be listed on
https://einax.com3. Listing token on einax.comThis part is easy. Simply drop us a message via Telegram with a link to your verified token smart contract.
Our telegram group is:
https://t.me/einax_exchangeOnce your token is listed on einax.com you may start distributing it via airdrops to a broad audience or create redeemable vouchers if you need more personalized approach. All services are free. We also plan to launch TOKEN/ETH trading pairs on November 1st, 2018. Your token will be listed on an exchange automatically.
If you have any further questions please feel free to ask here in this topic.
Cheers!
PS:
We've published a guide on how to launch your own AirDrops on einax platform. The good part is that you don't even have to deposit anything to test airdrops - every new account registered at einax.com receives 100 Welcome Tokens for free.