Learn Solidity: Basics of Solidity By Example

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] |
Related Articles
View AllSolidity
Learn Solidity: What’s Next?
Since now you have learned Solidity, you might be wondering what’s next? [shortcode id=”1983″] You should go & try below options: Create your own cryptocurrency Create a fully functional & professional crowd sale application Create a custom app of your own use case Learn…
Solidity
What is Solidity ABI (Application Binary Interface) & How does it work?
Solidity has recently become popular. Developers use the programming language to construct smart contracts for decentralized applications. On the Ethereum blockchain, Solidity is a favored
Ethereum
How to Learn Solidity and Become a Solidity Developer [UPDATED]
If you want to learn solidity language and become a certified solidity developer, this article illustrates how to start as a beginner and reach your goals. Introduction to Solidity Gavin Wood initially proposed the idea of Solidity in August 2014, which is a contract-oriented programming language…
Trending Articles
The Role of Blockchain in Ethical AI Development
How blockchain technology is being used to promote transparency and accountability in artificial intelligence systems.
AWS Career Roadmap
A step-by-step guide to building a successful career in Amazon Web Services cloud computing.
Top 5 DeFi Platforms
Explore the leading decentralized finance platforms and what makes each one unique in the evolving DeFi landscape.