A step by step guide on how Ethereum smart contracts work and how to code by yourself
Aug 27, 2017 Posted / 3131 Views
Smart contracts are the automated contracts which have started to revolutionize the business and financial world. These smart contracts are receiving a lot of attention because of the several distinct features. This decentralized tool has steadily started to prove like a boon for the industries. Let us know the working of this phenomenal creation:
Nick Szabo, was the man who had put this technology in fron of the world, in the year 1993. He basically described it as a digital vending machine. An example which was given by Nick said about the user can give Input value or the data and can receive numerous item from the machine. The Ethereum platform is specially designed for the better compatibility with the smart contracts.
These self automated contracts were initially created to support the transfer the value from one person to another over the network, where the nodes will validate the transactions if and only if certain types of conidtions are met, which are specified in the contract.
3. A user can make smart contracts on the Ethereum blockchain by doing a transaction without any destination address and having a portion of code to decide on what it does.
4. The smart contracts are then operated by Ethereum miners as regular blocks and attached to the blockchain, which will store the data permanently in the public distributed ledger.
5. In the future if anyone has an interaction with the contract, it will execute its code and produce other blocks to be added to the blockchain.
6. This method allows the Ethereum blockchain to operate as a virtual decentralized computer, on which the developers can make applications consisting of numerous smart contracts.
7. This smart contract is enabled by two important factors which are the Turing programming language called Solidity and an ether minimum price to execute the code.
8. The ether prices are necessary for the execution of the smart contract or to send a transaction, which is referred as the 'gas' price, to distinguish between the currency that empowers blockchain transactions from the cryptocurrencies which are used for payments.
9. All transactions have a least, typically minor, gas price which is obtained by the miners who process that block.
10. 'Gas' is frequently described as the fuel essential for the interaction with the Ethereum blockchain and grants a substantial value on the ether currency.
11. Solidity is a language created specifically for use in Ethereum smart contracts, which is a turing complete programming. Turing complete means the language can be used to solve any computational problem potentially and has the support for functions such as unlimited loops.
To code a successful smart contract by yourself you need a compiler and an Application Binary Interface, which is needed to tell the how the interaction with the smart contract will give result, by using Solc compiler
1. Install Geth on your computer and run the Geth client. It will take few moments to connect the network.
2. To test the solidity, run the 'eth.getCompilers()' command on the compiler.
3. To compile the smart contracts, first remove all the line breaks, you can can use various online tools for it, so that it fits into the string variable.
4. Use this command to compile the smart contracts:
var greeterSource = ‘the code without line breaks’
and then this one,
var greeterCompiled = web3.eth.compile.solidity(greeterSource)
5. After compiling it, enter a message of your choice in the geth's command line, you can also change the greeting message as you want.
6. You can use the Online Solidity compiler as well, instead of the Solc compiler.
7. In order to delete your smart contract, you will need to pay an amount of ether, which will cost much less than a conventional transaction, to apply changes on the blockchain, i.e. by using the 'self-destruct' function.
8. Use this command to delete your smart contract:
9. Every smart contract has to be deployed with the self-destruct clause, otherwise the smart contract will remain forever in the blockchain.
10. You can work on and create many other complex smart contracts as per your need.
Applancer is an open platform for discussion on all things like Blockchain , Cryptocurrency and Ico news updates. As such, the opinions expressed in this article are the author's own and do not necessarily reflect the view of Applancer .
Hottest Blockchain Newsletter
For updates and exclusive offers, enter your e-mail below.