Build your own criptocurrency with Ethereum
not only the Bitcoin a blockchain is made
Ethereum is a programmable blockchain with a decentralized platform to run your smart contracts, these contracts are executed in this blockchain and run exactly as scheduled without any possibility of speed drop, censorship, fraud or third party interference [ETHEREUM, 2017].
Ethereum has arrived with innovations, introducing smart contract and other ways that we can utilize a blockchain, not only for cryptocurrency, and with it a new world of possibilities is open. For you understand better all of this, I will show to you how create your own cryptocurrency and understand a little more about cryptocurrency.
What is Smart Contract?
Smart contracts can be described as highly programmable digital money. Imagine sending money automatically from one person to another, but only when a certain set of conditions are met.Imagine an example, in a real case you would enter into a contract with someone you have never met? Your answer to that question is probably no, and the reason for your answer is probably due the fact that a contract requires a great infrastructure: Sometimes you need a relationship that trust between the two parties, sometimes you depends on the legal work system, police force, lawyer costs, among other factors.
But in Ethereum you do not need any of this, if all the requirements can be placed in the blockchain then you will be in a reliable environment with a low cost.
What you need know to development
Installing what you need
Solidity is a language of programming for smart contract, a high-level language whose syntax is similar to javaScript and designed for Ethereum Virtual Machine (EVM).
Solidity is statically typed, supports inheritance, libraries and complex user-defined types, it is the most popular but not the only one, have other languages like Serpent, LLL and Mutan but the latter is no longer used [READTHEDOCS, 2017].
For create your own criptocurrency Ethereum you need install this language and/or some Solidity Integrations, how:
- REMIX this a Browser-based IDE;
- intelliJ IDEA plugin Solidity plugin for IntelliJ IDEA;
- visual Studio Extension Solidity plugin for Microsoft Visual Studio; e
- for more integrations consult this link: https://solidity.readthedocs.io/en/develop/.
Starting development
All figures below show classes that is one way to implement your criptocurrency.
Interface ERC20
Standard Token that describes what functions and events Ethereum token contract should implement, is represented in Figure 3:
So a little explanation about each method do:
totalSupply return how much tokens have this cryptocurrency.
balanceOf return how much token some user have.
tranfer basicaly receive two parameter, first is the address that you want send some value, and second is how much you can send.
transferFrom receive three parameters, from, to, and value, it is another way of transfer.
approve return if the transfer was finished with success.
allowance return how much token was remaining if spend some tokens.
This methods is basically to start your development and with this to auxiliary you, so you can elaborate more complex methods and understand better how work the Ethereum, based in this functions that you can elaborate new methods and create your own cryptocurrency, this was basically operations that will need. Events is very similar to functions but they are responsible to fire some action.
Why need to use the SafeMath library
To prevent overflow from occurring in any transfer operation, use the SafeMath library that will be displayed in Figure 4, this is more a recommendation, you don’t need this class for you, if you don’t want.
Complete Implementation of ERC20 token
Figure 5 and 6 show the complete implementation of interface in figure 3, you can change what you want, what was do in this code is only a suggestion what you can do, not a rule.
Additional code to turn your cryptocurrency in a crowdsale
To transform your ERC20 token into a crowdsale, you need to add the code available in figure 7, what it does is perform a different function when you send ether toward a contract without calling any specific function, it will transform the value of ether in a token amount of that contract.
Deploy of your cryptocurrency
The topics below will show what you need to deploy your smart contract.
Wallet
To deploy you will need a wallet, which can be created and accessed in various environments, with versions to install on your machine locally and also has online versions, and also with a plugin for the google chrome browser.
The chosen for this case was the Metamask plugin that is shown in figure 8, which has the advantage of a friendly interface, and does not need to download all blockchain from Ethereum, size of blockchain is approximately 20GB.
For curiosity in figure 9 is a wallet for install, and how you can see have a local where you can deploy your code and create your criptocurrency.
Get Ether for test in environment testnet
Is necessary to have Ether to be able to perform the operations to test the creation of the cryptocurrency, one way to get Ether is mining, or simply you can use real money to buy Ether [ETHEREUM DOCS, 2017].
Mining
Ethereum like any other technology blockchain uses an incentive-based security model, the consensus is based on the choice of the blockchain block with greater total difficulty. A block is only valid if it contains proof of worker (PoW) of a certain difficulty.
Any node participating in the internet can be mined and it is expected that your mining income will be commensurate with your mining power or hashrate.
The rewards for mining the “winning” block are:
- a static block as a reward for the “winning” block, which consists of exactly 5 Ether;
- cost of the gas that was spent with the block is recovered;
- an extra reward for including Uncle as part of the pack, in the form of an extra 1/32 per included uncle.
Uncles are obsolete blocks in which parents are ancestors. Validating uncles is rewarded in favor of neutralizing the lag effect.
The algorithm used is called Etash, it is designed to have a fast time of verification even in an environment that only counts on CPU, but if you have a large amount of memory and a large bandwidth it provides a great acceleration for mining .
After knowing a little more about how mining works in Ethereum, let’s go directly to what matters, like mining? You will need a fully synchronized Ethereum customer for mining and at least one Ethereum account, this account is used for you to receive your mining earnings.
Here are the three ways to mine, CPU mining, GPU mining, Pool mining:
- CPU mining: Using your CPU to mine Ether. In the matter of profitability is not recommended anymore, since GPU miners are two orders of magnitude faster. But the interesting thing about this possibility of mining with the CPU is to simply test your contracts since you can mining the Morden testnet or a private chain for the purpose of creating your own ether to test.
- GPU mining: This is implemented in OpenCL, so AMD video cards will be faster than NVDIA video cards of the same category.
- Pool mining: These are mining cooperatives that aim to smooth the expected income of participating miners. In return you will have to pay a fee that goes from 0–5% of your reward, the advantage is that the group will earn more rewards since it will have more PoW, and each miner will have his reward in relation to his contribution.
When working with pool mining is always important to be careful, as this usually involves a third party, and core components which means they are not reliable, roughly speaking, the pool mining operator may simply run away with their earnings [ETHEREUM DOCS, 2017].
Buying Ether
Buying Ether for real money, which can be done on trading platforms like: (https://iqoption.com/land/start-trading-crypto/en)
Final considerations
It’s seen that the technology of blockchain is often only seen as a crypto-currency and nothing more, however the possibilities and future of the same shows promise.
A financial system, such as the Stellar payment protocol. Data storage securely. Distribution of media, we imagine the following situation currently suffers from content piracy, however if content is posted by the owner in a blockchain avoids fraud and who could have access to it would be who the owner sends, so similar with the cryptocurrency. Have others possibilities of the use blockchain like electronic voting and personal identifiers.
In comparison with Bitcoin, your blockchain has a long confirmation interval, a need for high computational power, and a high energy expenditure.
In contrast, we have the blockchain of Ethereum that brought solutions to the problems in Bitcoin as the long interval of confirmation and centralization of the mining around few users, however its greater complexity in relation to the architecture of Bitcoin care a little in relation to maintain the level of security that Bitcoin has.
In the end one realizes that the future to say which cryptocurrency is better is uncertain, perhaps a new coin that joins the simplicity of Bitcoin with all the potential of the Ethereum[de Lucena et al].
The code is available in this link: https://github.com/BCecatto/EthereumExample
References
ETHEREUM, disponível em: ethereum.org, acessado em 13 de outubro de 2017.
ETHEREUM DOCS, disponível em: http://ethdocs.org/en/latest, acessado em 13 de outubro de 2017.
READTHEDOCS, disponível em: https://solidity.readthedocs.io/en/develop/, acessado em 16 de outubro de 2017.
de Lucena, Antônio Unias, and Marco Aurélio Amaral Henriques. “Estudo de arquiteturas dos blockchains de Bitcoin e Ethereum.”