This post was originally written in korean: https://steemit.com/kr/@mossid/5kv1hu
After yesterday when I wrote an introduceyourself, I had pondered what to write. I thought I have to write my first post cool, or start with simple post and increase gradually. At the end of the thought, I decided to write something I knew and spread the knowledge - Solidity.
What is Solidity? Many of steemian may already knows what Ethereum is. For those who dosen't know, Ethereum is
- A cryptocurrency
- Not just a cryptocurrency, but a platform that supports other cryptocurrencies and decentealized app (dapp) to be runned on it.
- Capable to run crowdfunding(especially ico), DAO, and even decentralized exchanges.
Solidity is a programming language that is designed for programming dapps.
So what can I do if I learn Solidity?
You can make dapps. Let me show you some of the existing dapps.
Token
This is from official Ethereum tutorial. Before Ethereum came out to the world, people had to write their own blockchain source code from scratch. But with Solidity, now they can implement a token with simple transfer functionality in <100 lines of code!
EtherDelta
EtherDelta is a decentralized exchange that runs on ethereum network. Dex model, represented by BitShares, is being popularized because it solves the problems of conventional exchanges, such as hacking and scam. However, due to the limitation of Ethereum network, EtherDelta stores transaction data only on Ethereum, and orderbook data is stored in seperated database(0xprotocol is using this method).
Augur
Augur is a prediction market running on Ethereum network. Prediction market is a future prediction model that makes people bet on future events and get rewarded when they make a right prediction. The price of shares is adjusted in this process and denotes the probablity od the future event. Because it is based on collective intelligence, sometimes it is more efficient to predict the future. For your information, Augur is not written in Solidity. It is written on Serpent, another Ethereum programming language.
Way to start Solidity programming
At the early stage of Ethereum, you need whole ethereum blockchain which requires a week to be sync to programming with Solidity and deploy a contract(automated adress owner that runs on Ethereum, just think it as more wider concept than dapp). Fortunately, now we have comfortable enviorments like MEW and Remix, so we will use them.
1. Open Remix.
Remix is online Solidity compiler. We are not going to learn real Solidity programming yet but just see the workflow, so just copy&paste the following code:
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint) {
return storedData;
}
}
Original: https://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
This code makes Ethereum blockchain to store a number(storedData
) and makes us to set
and get
it.
2. Deploy contract.
Remix does compile automatically, so right after you past the code there will be little delay and compilation will be completed. To deploy contract, click this create
button.
You don't have to pay ether to deploy contract because the blockchain Remix provides is not Ethereum mainnet. Instead, it makes some kind of little Ethereum(Javascript VM) for you. So you can't use this method when you are going to interact with real web.
3. Start debugging
After you clicked create
, the buttons to interact with the contract is visible.
You are now able to see uint256: 0
below get
, and a input filed next to set
. Do you remember that this contract stores a number? uint256: 0
means current stored value is 0, and this is because Ethereum set every value 0 initially.
Now let's set another value. Type 3(or any other number below 2^256) in the empy filed and click set
.
41662 gas is used in transaction, 20158 gas is used in execution. Ethereum requires gas in every command including deploy and calculation. In other words, complex calculation make you pay more ether. In this example, we are not using real blockchain, so there is no real payment of ether.
After then, click get
to check new value.
You can see it is showing 3.
Have you built anything cool with Solidity?
No, I'm still learning Solidity. My personal interest is in decentralized exchanges, so if I make something cool, it might be dex.
We need one so bad.