Do you have an excellent idea for an app? Maybe you want to establish a new, groundbreaking startup? Probably the first problem on your way to success will be to collect enough amount of money in blockchain.
Okey but it’s not only your problem and a lot of people managed to do it before. So you can ask ‘Uncle Google’ for help. For sure one of the first results will be to organize an ICO. But what is it?
What is more I want to cover more technical part to show how it works, which could be interesting for people who want to learn the Ethereum technology.
ICO
ICO (Initial Coin Offering) is a mechanism which allows you to collect cryptocurrency like BitCoin or Ether in exchange for your cryptocurrency or crypto-tokens. Simply speaking, it’s just an easy, based on popularity of cryptocurrencies, way to collect money from investors. You receive cryptocurrency and offer your token which maybe will have a real value in the future or will be just a souvenir for investors.
I want to show you what is behind most of ICOs now.
Bitcoin, cryptocurrencies, blockchain, Ethereum, …
You must have heard about Bitcoin and cryptocurrencies. And it’s not only the lines on the graph that make you lose when it goes down or earn when it raises. Behind it there is an interesting algorithm which goal is to make it trustworthy and secure. It turns out that using the same approach we can do more than only transferring coins. And as always in IT world, when there is a need, there is a group of people that prepare a framework for it.
Probably in this way Ethereum was born. Ethereum uses similar technologies to BitCoin, it simplifies exchanging everything in a way that BitCoin does it with coins. Of course it’s not the only tool to do it, but nowadays it is the most popular one.
Behind Ethereum (and BitCoin)
Personally, I hate using technology not knowing what is behind it. So this is a really brief description how it is realized. You can skip it if you already know, for example, how BitCoin/Ethereum works.
Blockchain
Really catchy word now. But it is just a way of holding information using, not surprisingly, a chain of blocks. The main idea is to decentralize everything to eliminate a person or an institution which we have to trust in (for example in the traditional banking we have to trust a bank). In this concept everybody has a copy of a database so everything is transparent and there isn’t a single person who can manipulate records in this database. If somebody did it, other users would reject his change. How is it realized? Using a simple one-directional list and a handful of cryptographic algorithms. Changes are added as the next block.
Mining
But how it is added? If we want to change something (make a transaction) we have to broadcast it to all other nodes in the Ethereum network. Then there are some special nodes called miners. Their task is to verify transaction and use some computational power to find an answer for a puzzle to confirm block of transactions. The first miner, that solves this, will receive a prize. And it makes it really hard to add manipulated block, because the potential attacker would have to have more computational power than the rest of the network, what is really expensive.
Keys
To confirm that you are you there is used pair of keys – private and public one. You sign transactions using the private key and then everybody can check that is was you using your public key. Nothing more than typical cryptographic algorithm, but it ensures than nobody can make transaction on your behalf.
How to create it?
Let’s make two most typical things in Ethereum – a token and an ICO. Ethereum uses a language called Solidity to write smart contracts. I won’t go into details of the syntax, I believe that it is pretty self-explanatory, even for a non-technical person.
Token
It is so popular and widely-used that there are even standards ‘how to create token’. But let’s start from the simplest implementation:
contract Token { mapping(address => uint) private balances; function balanceOf(address owner) public view returns (uint) { return balances[owner]; } function transfer(address to, uint amount) public returns (bool) { require(balances[msg.sender] >= amount); balances[msg.sender] -= amount; balances[to] += amount; return true; } }
I believe that this is really clear. We have a book (map technically speaking) called ‘balances’, where we keep current amount of coins for every account. We can check the current balance using the balanceOf() function. And the transfer() function in which we can give somebody some coins just by removing from our account and adding to theirs. Simple and insecure.
Problems
Coins from the air?
We can now exchange coins but we have to pose a question: ‘What was at the beginning?’. We have to setup an initial balance. There are two common approaches to do it: setup an initial balance which is immutable or add a mint function which only the owner of the token can invoke. Below there is the first way.
contract Token { uint private totalSupply; constructor(uint _initialAmount) public { totalSupply =_initialAmount; balances[msg.sender] = totalSuppply; } ... }
Long-time problem – overflows
The type uint in Solidity have 256 bits so it can hold really big numbers. But not infinite ones. There were a lot of attack based on integer overflow. To prevent it we can use SafeMath library which checks overflows for us. Typically zeppelin’s one.
contract Token { using SafeMath for uint; ... function transfer() public return (bool){ require(balances[msg.sender] >= amount); balances[msg.sender] = balances[msg.sender].add(amount); balances[to] = balances[to].sub(amount); return true; } }
Sending to contracts
One more problem occurs when we send tokens to contracts. There is a big possibility that they won’t be able to handle them. Then our coins will be stuck in this contract forever. And that leads us to tokens’ standards.
Token standards
The Ethereum community have established a lot of standards which determine functions that coins implementations should have.
ERC20
This is the basic token standard which can be recognized by other apps. Besides the basic functionality it also supports functions like approve() and transferFrom() which enable us to delegate an address that will be able to manage part of our wealth for us. It is a little bit deprecated because of the problem with sending tokens to contract. Here is the interface which contract should implement to follow this standard:
interface ERC20 { function totalSupply() external view returns (uint256); function balanceOf(address _who) external view returns (uint256); function allowance(address _owner, address _spender) external view returns (uint256); function transfer(address _to, uint256 _value) external returns (bool); function approve(address _spender, uint256 _value) external returns (bool); function transferFrom(address _from, address _to, uint256 _value) external returns (bool); }
Summary
There are many very successful ICOs using the Ethereum ecosystem. Personally, I think that it is a worth to consider and relatively safe option for collecting donations based on popularity of cryptocurrencies. What is more it isn’t hard and long to create it. After learning this technology and looking on some ICOs you can see that most of them are very similar and there are a lot of already created and tested libraries. Additionally, for me as a developer it was something new and interesting to learn. I covered only very basics in this article but I hope that I encouraged you to consider ICO as a fund-raising mechanism or to learn more about this technology.
Our mission is to support startups in achieving success. Feel free to reach out with any inquiries, and visit our blog for additional tips. Tune in to our podcast to glean insights from successful startup CEOs navigating their ventures.