{"id":20059,"date":"2022-10-02T18:09:37","date_gmt":"2022-10-02T18:09:37","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=9167"},"modified":"2022-10-02T18:09:37","modified_gmt":"2022-10-02T18:09:37","slug":"solidity-for-contract-writing","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/10\/02\/solidity-for-contract-writing\/","title":{"rendered":"Solidity for Contract Writing"},"content":{"rendered":"\n<p>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).<\/p>\n\n\n\n<p>For quick understanding of the Solidity syntax, look at the sample code in the IDE.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pragma solidity &gt;=0.4.22 &lt;0.6.0;\ncontract Ballot {\n<\/code><\/pre>\n\n\n\n<p>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 \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>address chairperson;\n<\/code><\/pre>\n\n\n\n<p>You can also define structures such as&nbsp;<strong>Proposal<\/strong>&nbsp;and create an array of these structure items. Examine this in the code window.<\/p>\n\n\n\n<p>You may then define a constructor which is invoked at the time of instantiating a contract.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>constructor(uint8 _numProposals) public {\n<\/code><\/pre>\n\n\n\n<p>After the constructor, you will define several methods, which are the contract methods. In the sample contract,&nbsp;<strong>giveRightToVote<\/strong>&nbsp;is one such method having the following syntax \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function giveRightToVote(address toVoter) public {\n<\/code><\/pre>\n\n\n\n<p>The&nbsp;<strong>public<\/strong>&nbsp;keyword makes this method publicly invokable by any client who has access to the contract.<\/p>\n\n\n\n<p>Likewise, the sample contract defines three more methods called&nbsp;<strong>delegate, vote<\/strong>, and&nbsp;<strong>winningProposal<\/strong>. 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/20059"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=20059"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/20059\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=20059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=20059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=20059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}