{"id":20060,"date":"2022-10-02T18:11:20","date_gmt":"2022-10-02T18:11:20","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=9169"},"modified":"2022-10-02T18:11:20","modified_gmt":"2022-10-02T18:11:20","slug":"developing-mycontract","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/10\/02\/developing-mycontract\/","title":{"rendered":"Developing MyContract"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/mdr.foobrdigital.com\/wp-content\/uploads\/2022\/10\/loan-1.png\" alt=\"\" class=\"wp-image-9170\"\/><\/figure>\n\n\n\n<p>We will name our contract&nbsp;<strong>MyContract<\/strong>&nbsp;as in the following declaration \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>contract MyContract {\n<\/code><\/pre>\n\n\n\n<p>We will declare two variables as follows \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uint amount;\nuint value;\n<\/code><\/pre>\n\n\n\n<p>The variable&nbsp;<strong>amount<\/strong>&nbsp;will hold the accumulated money sent by the contract executors to the contract creator. The&nbsp;<strong>value<\/strong>&nbsp;field will hold the contract value. As the executors execute the contract, the&nbsp;<strong>value<\/strong>&nbsp;field will be modified to reflect the balanced contract value.<\/p>\n\n\n\n<p>In the contract constructor, we set the values of these two variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>constructor (uint initialAmount, uint initialValue) \npublic {\n   amount = 0;\n   value = 1000;\n}<\/code><\/pre>\n\n\n\n<p>As initially, the amount collected on the contract is zero, we set the&nbsp;<strong>amount<\/strong>&nbsp;field to 0. We set the contract&nbsp;<strong>value<\/strong>&nbsp;to some arbitrary number, in this case it is 1000. The contract creator decides this value.<\/p>\n\n\n\n<p>To examine the collected amount at any given point of time, we provide a public contract method called&nbsp;<strong>getAmount<\/strong>&nbsp;defined as follows \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function getAmount() public view returns(uint) {\n   return amount;\n}<\/code><\/pre>\n\n\n\n<p>To get the balanced contract value at any given point of time, we define&nbsp;<strong>getBalance<\/strong>&nbsp;method as follows \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function getBalance() public view returns(uint) {\n   return value;\n}<\/code><\/pre>\n\n\n\n<p>Finally, we write a contract method&nbsp;<strong>(Send)<\/strong>. It enables the clients to send some money to the contract creator \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function send(uint newDeposit) public {\n   value = value - newDeposit;\n   amount = amount + newDeposit;\n}<\/code><\/pre>\n\n\n\n<p>The execution of the&nbsp;<strong>send<\/strong>&nbsp;method will modify both&nbsp;<strong>value<\/strong>&nbsp;and&nbsp;<strong>amount<\/strong>&nbsp;fields of the contract.<\/p>\n\n\n\n<p>The complete contract code is given below \u2212<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>contract MyContract {\n   uint amount;\n   uint value;\n\n   constructor (uint initialAmount, uint initialValue) public {\n      amount = 0;\n      value = 1000;\n   }\n   function getBalance() public view returns(uint) {\n      return value;\n   }\n   function getAmount() public view returns(uint) {\n      return amount;\n   }\n   function send(uint newDeposit) public {\n      value = value - newDeposit;\n      amount = amount + newDeposit;\n   }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We will name our contract&nbsp;MyContract&nbsp;as in the following declaration \u2212 We will declare two variables as follows \u2212 The variable&nbsp;amount&nbsp;will hold the accumulated money sent by the contract executors to the contract creator. The&nbsp;value&nbsp;field will hold the contract value. As the executors execute the contract, the&nbsp;value&nbsp;field will be modified to reflect the balanced contract value. [&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\/20060"}],"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=20060"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/20060\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=20060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=20060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=20060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}