In this blog post we will create our own Ethereum ERC20-Token, which could be used for an ITO (Initial Token Offering) and could be traded on the Ethereum Blockchain.
Furthermore we will cover some core concepts (Blockchain, Ethereum, ...), terms (Security Token vs. Utility Token, Coin/Cryptocurrency...) and standards (e.g. ERC20).
A blockchain is an audit-proof digital general ledger of transactions which can record not only financial transactions, but virtually any type of transaction.
A blockchain is thus, in the simplest sense, a series of immutable records including time stamps, managed by a decentralized network of computers that do not belong to a single organization or person (compared to a central server under the full control of a single organization or person).
These data sets ("blocks") are linked by cryptographic principles ("chains").
A blockchain is therefore a basically simple, but potentially disruptive way of verifying transactions. A party to such a transaction initiates the process by creating a block. This block is checked and confirmed by the computers distributed in the network. The verified block is then added to the chain, which is stored throughout the network, creating not just a single unique record, but a unique record including a unique history - attempting to forge a single record would mean falsifying the entire chain in potentially millions of cases.
Such a blockchain network is therefore not subject to any central authority - since it is a decentralized and unchangeable general ledger, the information in it (i.e. the respective transactions) is visible to everyone, for example the entire transaction history of a physical or digital good or right.
The cryptocurreny Bitcoin uses this model for payment transactions, but it can also be used in many other ways and is basically potentially suitable for all those applications in which a neutral, timely and audit-proof confirmation of transactions - such as the signing of a contract or the change of ownership of physical or digital goods or rights - is required.
In principle, transactions on such blockchains are free of charge - what usually does incur costs is infrastructure. This is usually covered by the fact that, for example, the initiator of a transaction promises so-called "gas" for those computers in the network that confirm the transaction, as motivation for the operators of those nodes to make their computing power available to the network. On the Ethereum Blockchain this gas is paid in the cryptocurrency ETH (Ether), so the costs in "common" currency (e.g. Euro) depend on the respective exchange rate of ETH. At the time of writing this article, such a transaction confirmation within about 2 minutes on the Ethereum Blockchain costs about € 0.012, a confirmation within about 5 minutes about € 0.0045. The more computers in the network confirm the transaction, the more secure (in the sense that it took place) it can be considered.
In comparison to offline processes - for example a notary who confirms a transaction - this results in the potential to significantly reduce costs and time expenditure for such sensitive transactions on the one hand, while on the other hand aspects of audit security and transparency are increased.
The easiest way to describe Ethereum is as an open software platform based on blockchain technology that allows developers to create and deploy distributed applications.
Like Bitcoin, Ethereum is a distributed public blockchain network. Although there are some significant technical differences between the two, the most important difference is that Bitcoin and Ethereum differ significantly in purpose and capability. Bitcoin offers a specialized application of blockchain technology, a peer-to-peer e-payment system that enables online Bitcoin payments.
So while the Bitcoin blockchain is used to track the ownership of the digital currency (Bitcoins), the Ethereum blockchain focuses on the execution of program codes of any distributed application.
In the Ethereum blockchain, so-called Ether (ETH), a crypto token that drives the network, are earned for providing computing power ("mining"). In addition to its role as a tradable crypto currency, Ether is also used by application developers to pay transaction fees and services in the Ethereum network.
As described at the beginning of this article, the Ethereum blockchain enables the use of tokens which can be bought, sold and traded by users. These should not be confused with Ether (ETH), which is "only" the natural currency of the Ethereum Blockchain infrastructure as described above.
Tokens are digital assets or programs based on the blockchain. These tokens serve the purpose of attributing a value to them, such as promissory notes, profit participation rights, services or real objects. Hence tokens are generally not to be confused with crypto currencies (for example Bitcoin or Ether). Tokens are basically so-called "Smart Contracts", which in the case of ERC20 are executed on the Ethereum block chain.
Introducing the ERC20 standard, Ethereum first issued technical specifications for a token on its blockchain in 2015, where "ERC" stands for "Ethereum Request for Comments". ERC20 is therefore a standard protocol that defines the properties and functionality of an Ethereum blockchain token.
A token in general is basically simply a digital representation of potentially anything. For example, a token can represent a stock, a bond, an option, or a property etc. A token can also represent access rights to a blockchain or blockchain app, and tokens can also be used to automate "friction points" in various industries.
Utility tokens, are tokens that have a specific "use" on the blockchain or an app based on that. Utility tokens are also called "app coins" because they are explicitly designed for a certain app or blockchain.
For this reason, utility tokens are intended exclusively for such specific use and are not an investment instrument.
Security tokens, on the other hand, represent investments, such as securities such as shares, bonds, funds etc., digitally. Thus, securities of companies, fund houses or real estate funds, which are issued via the blockchain, are referred to as security tokens. As is the case with traditional "securities", security tokens thus represent profit participation, interest income or give voting rights or generate profits for the holders of those tokens.
While security tokens must therefore be subject to various regulations and legal frameworks to which the issuer must adhere, this does not apply to 100% utility tokens.
2.1.1 MetaMask
MetaMask (https://metamask.io/) is a browserextension (Chrome, Firefox, Opera) which makes it possible to run Ethereum dApps directly in the browser and without having to run a full Ethereum-Node.
MetaMask thus makes it possible to manage identities on different websites and sign blockchain transactions.
2.3.2 Remix - Ethereum IDE
Remix (http://remix.ethereum.org) is an online-compiler which enables us to deploy our following Smart Contract directly onto the Ethereum-Blockchain.
2.3.3 ERC20-Token Smart Contract
The following is an exemplary (use at your own risk!) Smart-Contract, which can be adapted as described below in the next step to create your own ERC20 token. (Source: Token Factory and @maxnachamkin)
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^256 - 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; //Name of the token uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals string public symbol; //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 ERC20Token function ERC20Token( ) { balances[msg.sender] = NUMBER_OF_TOKENS; // Give the creator all initial tokens (100000 for example) totalSupply = NUMBER_OF_TOKENS; // Update total supply (100000 for example) name = "NAME_OF_TOKEN"; // Set the name for display purposes decimals = DECIMALS; // Amount of decimals symbol = "SYM"; // 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; } }
The following parameters should be adjusted:
NUMBER_OF_TOKENS
The total number of tokens issued, for example 100 (and in this case also the number of tokens which the creator will initially hold in his wallet).DECIMALS
The number of decimal places and thus definition of the maximum divisibility of the token, for example 18NAME_OF_TOKEN
The display name of the token, for example "Axom Token".SYM
Abbreviation of the token, for example "AXM".The above Smart-Contract-Code can be copied and pasted into the main window of Remix (http://remix.ethereum.org) after the individual adjustments described above.
In the tab "Run" the Smart-Contract can now be deployed to the Ethereum blockchain. The total number of tokens defined in the Smart-Contract-Code (e.g. 100) should be associated with and held in the MetaMask Wallet (from which they could be traded in the next step).
The following values should be considered in the corresponding fields before deployment:
Environment
"Injected Web3"Account
Should match your MetaMask Wallet-AddressThe screen should hence look as follows:
With a click on "Deploy" and subsequent confirmation, the Smart-Contract can be deployed; after the transaction has been confirmed by the Ethereum-Blockchain-Network (note: this can take a couple of minutes), the defined number (e.g. 100) of issued tokens should then appear in the MetaMask Wallet.
Our emitted tokens should now be found in our MetaMask Wallet, which should look like this (Note: in the screenshot below there are only 99 tokens left, because a token had already been traded when this article was created):
By clicking on "Send", a definable number of the ERC20 token can now be sent to any ETH wallet; the screen for this should then look as follows:
Note: As described at the beginning of this article, all transactions on a blockchain, in this case the Ethereum blockchain, are transparently visible. For the Ethereum-Blockchain there exists http://etherscan.io/, an Ethereum-Blockchain-Explorer.
The transactions made by the author in the context of this tutorial can also be viewed: 1. deployment of the Smart-Contract and 2. trade of an AXM Token.
Tags
Table of Content
Comments
No comments yet