Starting with Solidity
We’re going to build and deploy an Ethereum smart contract.
As there are a lot of things to cover, this post will be followed by many others, so stay tuned.
1. Dip your toe into Solidity
CryptoZombies is a fun way to go through Solidity basics. It only takes I highly recommend it.
2. Use remix to write your own smart contract
Remix is a browser-based Solidity compiler and IDE.
Using the remix IDE you can write Solidity smart contracts, without having to install any software on your computer.
We will use the Coin
starter code, which can be found in the Solidity documentation:
pragma solidity ^0.4.0;
contract Coin {
// The keyword "public" makes those variables
// readable from outside.
address public minter;
mapping (address => uint) public balances;
// Events allow light clients to react on
// changes efficiently.
event Sent(address from, address to, uint amount);
// This is the constructor whose code is
// run only when the contract is created.
function Coin() public {
minter = msg.sender;
}
function mint(address receiver, uint amount) public {
if (msg.sender != minter) return;
balances[receiver] += amount;
}
function send(address receiver, uint amount) public {
if (balances[msg.sender] < amount) return;
balances[msg.sender] -= amount;
balances[receiver] += amount;
Sent(msg.sender, receiver, amount);
}
}
Compile, run and test your functionality
By default remix will auto-compile the smart contract you have saved. Below is a quick tour of the remix UI:
At the beginning, run your smart contract using theEnvironment
set as JavaScript VM
. It has the advantage of not being tied to a blockchain, everything is in the browser's memory.
You can use any of the accounts in the list to test transactions between multiple Ethreum
addresses. Note that the address which creates the coin is the owner of the smart contract deployed (is the msg.sender
and the only one that can mint new coins, as declared in the mint
function).
Where to go next:
- Solidity documentation
- Remix documentation
- Ethereum smart contract best practices
- Writing better Solidity code
- Use a framework for writing your smart contracts (e.g. truffle)
Congratulations @ruxu! You received a personal award!
Click here to view your Board
Congratulations @ruxu! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!