- 18 April, 2017
- Posted by: toshendra
- Category: Blockchain, Development, Solidity
Notice: This is one of the multi-post series of Learn Solidity - Build Decentralized Application in Ethereum. This is an attempt to teach you all about Solidity - A Programming Language for Ethereum Based Smart Contracts. If you want to take this as a video course please signup using below button.
As you can see in the above code, which is a simple smart contract written in Solidity for a new Coin. Here this Coin can be used to trace any digital asset which has a value.
Let’s go through the contract and understand it properly.
In line number 1 we have written the pragma which tells the compiler that this contract is written for solidity compiler version 0.4.8 or older. So if your compiler version is 0.4.9 this contract will through an error.
Then we have created a contract, specified the developer related comments, defined two public state variables minter & totalCoins of address & uint256 type respectively.
created a mapping aka array where address type will be the key & uint will be the value. We then created a constructor which will be called while initializing the contract. Then we defined the functions for the currency related operations & at last in line number 46, we created a kill function which will destroy the contract only if it is called by the minter (kind of admin).
You can then execute this contract as per the instruction in this article.
In this contract, we simply created a digital asset called “Coins” which is initialized with an initial supply. Here the executor will become the minter/admin. Then we wrote the function to send the Coins to an address & also to query the balance of an address. We have also written the function to create the new coins out of this air using the mint function.
|Next: Layout of the Solidity Source File|