The total market capitalization of the global cryptocurrency market over the last year has grown from $ 6 billion (in January 2016) to $ 28 billion (currently). Since the beginning of 2017, the cryptocurrency market has grown by about one and a half times. More than a hundred different cryptocurrencies are being traded on the exchanges. Large organizations are consortium to issue their own currency. Even states make their own national cryptocurrencies. Blockchain technologies have reached such a level that almost anyone can already launch their own cryptocurrency, which we will do in this article. The easiest way to create your own coins on ethereum-based smart contracts.
Going to the largest cryptocurrency exchange at the moment, you can find for example the following currencies at the top of the list: GNT (Golem), REP (Augur).
Although they are on the same list as Bitcoin (the first and most famous cryptocurrency) and Ethereum (the second most popular and capitalized currency) - they are not independent cryptocurrencies in their classical sense. They are crypto-tokens (tokens or assets) based on the ethereum blockchain.
A list of such tokens can be found for example here , there you can also find statistics on them.
Such tokens are usually needed for the following: some company wants to release a product that needs some internal currency. Also this company wants to conduct ICO (Initial Coin Offering), i.e. raise money for the project by pre-selling tokens to investors. So these tokens appear. The advantages here directly expire from the advantages of the blockchain and smart contracts: transparency, security and distribution.
For example, look at one of the first such companies Golem . Its essence is as follows: when we need computing power, we can not go to Amazon (Azure, Google ...), but rent a computer from another network member, paying off GNT tokens with it. Accordingly, you can also rent your computer and get a certain amount of GNT. Then these tokens can either be spent within the network, or sold on the exchange. Some tokens can bring dividends, or give the right to vote in the ongoing elections on any issues related to the company's product (this is implemented on smart contracts).
Golem, releasing 1,000,000,000 tokens, was able to attract 820,000 ETH, which is about $ 32,800,000 for current courses, but at the time of their ICO rate was 3 times worse.
Now I will tell you how to make your own cryptocurrency (tokens) based on Ethereum.
The current standard is the ERC20 described here .
The interface usually looks something like this:
/* * ERC20 interface * see https://github.com/ethereum/EIPs/issues/20 */ contract ERC20 { uint public totalSupply; function balanceOf(address who) constant returns (uint); function transfer(address to, uint value); function allowance(address owner, address spender) constant returns (uint); function transferFrom(address from, address to, uint value); function approve(address spender, uint value); event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); }
And the implementation is like this:
contract StandardToken is ERC20 { string public constant name = "Token Name"; string public constant symbol = "TKN"; uint8 public constant decimals = 18; mapping (address => mapping (address => uint)) allowed; mapping (address => uint) balances; function transferFrom(address _from, address _to, uint _value) { var _allowance = allowed[_from][msg.sender]; // Check is not needed because safeSub(_allowance, _value) will already throw if this condition is not met // if (_value > _allowance) throw; balances[_to] +=_value; balances[_from] -= _value; allowed[_from][msg.sender] -= _value; Transfer(_from, _to, _value); } function approve(address _spender, uint _value) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); } function allowance(address _owner, address _spender) constant returns (uint remaining) { return allowed[_owner][_spender]; } function transfer(address _to, uint _value) { balances[msg.sender] -= _value; balances[_to] += _value; Transfer(msg.sender, _to, _value); } function balanceOf(address _owner) constant returns (uint balance) { return balances[_owner]; } }
We will analyze in more detail.
This is the current number of coins issued:
uint public totalSupply;
Find out the balance at:
function balanceOf(address who) constant returns (uint);
We transfer our tokens to someone else:
function transfer(address to, uint value);
We find out how many coins we are allowed to spend from someone else's account. These permissions are managed by the approve function described below:
function allowance(address owner, address spender) constant returns (uint);
We translate foreign tokens that are available to us to someone else:
function transferFrom(address from, address to, uint value);
We allow someone to use our tokens. But these tokens remain with us. There are no restrictions on the number of accounts that will be allowed to use our tokens:
function approve(address spender, uint value);
Events that someone transferred tokens and that someone allowed to use their tokens:
event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value);
Full token name:
string public constant name = "Token Name";
Short name of token:
string public constant symbol = "TKN";
Number of decimal places. There are 18 in ETH, but you can put another number
uint8 public constant decimals = 18;
Dictionary address -> number of tokens:
mapping (address => uint) balances;
The dictionary is accessible to someone else tokens:
mapping (address => mapping (address => uint)) allowed;
That's basically it. But in this type of smart contract is useless, because Now does not provide for the creation of tokens and their number will always be zero.
Add a constructor that will create 1,000,000 tokens and transfer them to the owner of the smart contract. Also, it would not hurt to accompany all mathematical operations with overflow checks, but here I’ll miss it.
function StandardToken(){ balances[msg.sender] = 1000000; }
It would not hurt to add a function that allows you to buy tokens. For simplicity, we will mint tokens at the rate of 1 to 1, i.e. for 1 ETH we will charge 1 our token.
It may look like this:
function mint() payable external { if (msg.value == 0) throw; var numTokens = msg.value; totalSupply += numTokens; balances[msg.sender] += numTokens; Transfer(0, msg.sender, numTokens); }
It remains to publish it in the blockchain. After that you can send these tokens to other accounts.
Useful links on the topic:
Source: https://habr.com/ru/post/326626/