- Toshendra Kumar Sharma
- October 14, 2022
In this post, we will learn the Solidity language by going through two example. Then we will dig deeper into each & every aspect of Solidity & Blockchain-based development.
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.
We then declared two events on line 14 & 15. Events will be used to inform the monitoring entities or wallets.
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.
Solidity follows the syntax of JavaScript hence most of the syntax is similar except at few places.
[otw_shortcode_button href=”https://www.toshblocks.com/solidity/layout-solidity-based-smart-contracts/” size=”large” icon_type=”general foundicon-right-arrow” icon_position=”right” shape=”radius” color_class=”otw-green”]Next: Layout of the Solidity Source File[/otw_shortcode_button] |