Blockchain

How to Create a Cryptocurrency Token | by Kevin Gabeci | Level Up Coding

This article will serve as a tutorial for creating your own cryptocurrency token. We will be using Etherum’s “ERC-20” token as a basis for our code. Once we are finished you can use it to represent currencies or anything that you want to be tradable and have a fixed supply in circulation. This should go without saying but having knowledge in coding is really beneficial here to understand completely what we are doing through the whole process.

Photo by Clifford Photography on Unsplash

Metamask wallet serves as a gateway to blockchain apps and this is one of the first things that you have to do to get started. It’s an extension for your browser and be sure to only use Google Chrome for this. You will have to create an account and write down a 10-word pneumatic code.

Click here to download the extension.

Like you see in the picture above I already have added 1 Ethereum and that is because when we create the token we are going to use some of Ethereum as fees. It’s called the Gas Fee and its a fee for using their blockchain to transfer your tokens. This website allows you to request at least 1 Ethereum from their faucet.

Click here to Get 1 Ethereum.

To start the creation process of your token you need to go to this website. After opening it follow the steps below.

Click on the + Button on Top Left of the website to create a new file.

Name it whatever you want your token to be but don’t remove .sol in the end.

Then paste this code in the code editor.

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 function balanceOf(address _owner) constant 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) returns (bool success) {}/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @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) returns (bool success) {}/// @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 (uint256 remaining) {}event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value);}contract StandardToken is Token {function transfer(address _to, uint256 _value) returns (bool success) { //Default assumes totalSupply can’t be over max (2²⁵⁶ — 1). //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn’t wrap. //Replace the if with this one instead. //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { 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) returns (bool success) { //same as above. Replace this line with the following if you want to protect against wrapping uints. //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) { if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { 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 returns (uint256 remaining) { return allowed[_owner][_spender]; }mapping (address => uint256) balances; mapping (address => mapping (address => uint256)) allowed; uint256 public totalSupply;}contract ERC20Token is StandardToken {function () { //if ether is sent to this address, send it back. throw; }/* Public variables of the token */ string public name = “AmaBox”; //Name of the token uint8 public decimals = 3; //How many decimals to show. ie. There could 1000 base units with 3 decimals string public symbol =”AMA”; //An identifier: eg AXM string public version = ‘H1.0’; //human 0.1 standard. Just an arbitrary versioning scheme.//// CHANGE THE FOLLOWING VALUES FOR YOUR TOKEN!////make sure this function name matches the contract name above. So if you’re token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Tokenfunction ERC20Token( ) { balances[msg.sender] = 10000; // Give the creator all initial tokens (100000 for example) totalSupply = 50000; // Update total supply (100000 for example) name = “AmaBoX”; // Set the name for display purposes decimals = 3; // Amount of decimals symbol = “AMA”; // Set the symbol for display purposes }/* Approves and then calls the receiving contract */ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value);//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn’t have to include a contract in here just for this. //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData) //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead. if(!_spender.call(bytes4(bytes32(sha3(“receiveApproval(address,uint256,address,bytes)”))), msg.sender, _value, this, _extraData)) { throw; } return true; }}

You have to edit your code specifications and make it your own by replacing these fields in the code.

  • NUMBER_OF_TOKENS The total number of tokens issued, (and in this case also the number of tokens which the creator will initially hold in his wallet).In this case 10000
  • DECIMALS The number of decimal places and thus the definition of the maximum divisibility of the token, in our case 3.
  • NAME_OF_TOKEN The display name of the token, for example, “AmaBox.
  • SYM Abbreviation of the token, for example, “AMA”.

Now that we also have edited the code the next step is to change the network that you are on to Ropsten.

In the Compile tab, Select the compiler version 0.4.25 and make sure Auto Compile is turned ON, and Enable Optimization is turned OFF.

Now go back to Run Tab and click Deploy after selecting ERC20Token.

Now you have to wait for a minute until it processes the information and you should see a popup from the widget saying transaction confirmed. To verify that information click on the MetaMas widget, Settings and View on Etherscan.

You can see your account’s transactions and there it is Contract Creation, click on it and copy its address.

Go to your wallet and click on Add Token. From the popup that comes after clicking the button go to Custom Token tab and paste the contract address. Now if everything went okay you should also see your tokens in the wallet.

Now every step is finished and your Token is up and running on the Ropsten Network and if you want to make a new one but to run on Ethereum Network you need to pay something like 30$ but the steps are the same.

If you have any questions or suggestions about the article don’t hesitate to leave a reply in the comment section. Enjoyed what you read? Why not follow my Medium newsletter so that you don’t miss out on any of my future articles? It’s simple, click here enter your email address and press subscribe.

Do you enjoy reading articles on Medium? Consider becoming a member, there are a lot of features and you will get access to content from all creators for just $5 a month. Use this link and you also help me out to earn a small commission, click become a member, and enter your information.

Related Articles

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker