Solidity for Contract Writing

Solidity is an object-oriented language especially developed for contract writing. It is a high-level language, which inherits traits from C++, Python, and JavaScript. The Solidity compiler compiles your source code into bytecode that runs on Ethereum Virtual Machine (EVM).

For quick understanding of the Solidity syntax, look at the sample code in the IDE.pragma solidity >=0.4.22 <0.6.0; contract Ballot {

The first line is a directive to the compiler. The second line starts the definition of the contract. Within the contract, you declare variables such as −address chairperson;

You can also define structures such as Proposal and create an array of these structure items. Examine this in the code window.

You may then define a constructor which is invoked at the time of instantiating a contract.constructor(uint8 _numProposals) public {

After the constructor, you will define several methods, which are the contract methods. In the sample contract, giveRightToVote is one such method having the following syntax −function giveRightToVote(address t+oVoter) public {

The public keyword makes this method publicly invokable by any client who has access to the contract.

Likewise, the sample contract defines three more methods called delegate, vote, and winningProposal. Examine these for your own understanding of the Solidity syntax. These are the prerequisites to writing your own contract. Explaining the full syntax of Solidity is beyond the scope of this tutorial.

Similar Posts

  • MyEtherWallet

    For client application, you will use MyEtherWallet. Download MyEtherWallet software from the following URL − If required, unzip the downloaded file and open index.html. You will see the following interface for creating a new wallet.

  • Limitations of Remix

    The Remix IDE that you have used so far is good enough for development and initial testing of your contract. For real-life contracts, you need to test your functionality against various parameters. Remix cannot create real (non-test) user accounts to transfer funds between them. You have no control over the configuration of the Blockchain created…

  • Creating Wallet

    In this chapter, we will learn how to create Ethereum wallet. To create a new wallet, enter a password of your choice and then click on the “Create New Wallet” button. When you do so, a Wallet would be created. A digital wallet is essentially the generation of a public/private key pair that you need…

  • A Quick Walkthrough

    We will now briefly understand what is available on the Ganache desktop. On the Desktop, at the top we have several menu options out of which a few are of immediate relevance to us. The menu bar is highlighted in the screenshot below − Clicking on the TRANSACTIONS menu shows all the transactions performed so far. You…

  • Summary

    You learned how to write your own digital contract in Solidity. You developed and tested the contract interface in the Remix IDE. For further multi-user testing, you deployed this contract on Ganache Blockchain. On Ganache, you created two user accounts. The first account was used for publishing the contract. The second account was used for…