<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Odutola Abisoye</title>
    <description>The latest articles on DEV Community by Odutola Abisoye (@odutolaabisoye).</description>
    <link>https://dev.to/odutolaabisoye</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F457405%2F4d0060d3-be3b-4e03-be11-21b652db0bad.jpeg</url>
      <title>DEV Community: Odutola Abisoye</title>
      <link>https://dev.to/odutolaabisoye</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/odutolaabisoye"/>
    <language>en</language>
    <item>
      <title>SHORT: What is the difference between PURE and VIEW modifiers in Solidity?</title>
      <dc:creator>Odutola Abisoye</dc:creator>
      <pubDate>Fri, 24 Jun 2022 03:56:44 +0000</pubDate>
      <link>https://dev.to/odutolaabisoye/short-what-is-the-difference-between-pure-and-view-modifiers-in-solidity-4eih</link>
      <guid>https://dev.to/odutolaabisoye/short-what-is-the-difference-between-pure-and-view-modifiers-in-solidity-4eih</guid>
      <description>&lt;h2&gt;
  
  
  Function modifiers
&lt;/h2&gt;

&lt;p&gt;You want to create a function without actually changing the state in Solidity — e.g. it doesn’t change any values or write anything.&lt;/p&gt;




&lt;p&gt;&lt;code&gt;VIEW&lt;/code&gt; indicates that the function will not alter the storage state in any way but view only&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PURE&lt;/code&gt; indicate that it will not read the storage state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
---

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract ViewAndPure {
    uint public x = 1;

    // Promise not to modify the state.
    function addToX(uint y) public view returns (uint) {
        return x + y;
    }

    // Promise not to modify or read from the state.
    function add(uint i, uint j) public pure returns (uint) {
        return i + j;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  SUMMARY
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;VIEW&lt;/strong&gt; A read-only function, which ensures that state variables cannot be modified after calling them. If the statements which modify state variables, emitting events, creating other contracts, using selfdestruct method, transferring ethers via calls, Calling a function which is not ‘view or pure’, using low-level calls, etc are present in view functions then the compiler throw a warning in such cases. By default, a get method is view function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PURE&lt;/strong&gt; The pure functions do not read or modify the state variables, which returns the values only using the parameters passed to the function or local variables present in it. If the statements which read the state variables, access the address or balance, accessing any global variable block or msg, calling a function which is not pure, etc are present in pure functions then the compiler throws a warning in such cases.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you call view or pure functions externally, you do not pay a gas fee.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Handle Errors With Solidity - Require vs Revert - What you should know in 2022 on Solidity Error</title>
      <dc:creator>Odutola Abisoye</dc:creator>
      <pubDate>Wed, 22 Jun 2022 02:24:02 +0000</pubDate>
      <link>https://dev.to/odutolaabisoye/require-vs-revert-what-you-should-know-in-2022-on-solidity-error-2i3e</link>
      <guid>https://dev.to/odutolaabisoye/require-vs-revert-what-you-should-know-in-2022-on-solidity-error-2i3e</guid>
      <description>&lt;p&gt;Solidity &lt;code&gt;assert&lt;/code&gt; and &lt;code&gt;require&lt;/code&gt; are convenience functions that check for conditions. In cases when conditions are not met, they throw exceptions.&lt;/p&gt;




&lt;h2&gt;
  
  
  REQUIRE
&lt;/h2&gt;

&lt;p&gt;Require is reserved for error-conditions of incorrect input data to functions (when compared to expected/valid input data) that can not be detected until execution time. This correspond to function preconditions in programming language argot. The compiler is unable to help due to the infinite possibilities of input data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the REQUIRE Function will do&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate user inputs&lt;/li&gt;
&lt;li&gt;Validate the response from an external contract&lt;/li&gt;
&lt;li&gt;Validate state conditions prior to executing state changing operations, for example in an owned contract situation&lt;/li&gt;
&lt;li&gt;Require is used more often&lt;/li&gt;
&lt;li&gt;Use at the beginning of the function&lt;/li&gt;
&lt;li&gt;Allow you to return an error message.&lt;/li&gt;
&lt;li&gt;Refund any remaining gas to the caller.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;CODE EXAMPLE&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Error {
    function errorRequire(uint _i) public pure {
      require(_i &amp;lt;=10, "i must be greater than 10");
      // code
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Require should be used to validate conditions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;inputs&lt;/li&gt;
&lt;li&gt;conditions before execution&lt;/li&gt;
&lt;li&gt;return values from calls to other functions&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  REVERT
&lt;/h2&gt;

&lt;p&gt;Revert is reserved for error-conditions that affect business-logic. For example someone sends a vote when the voting is already close.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What the REVERT Function will do&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Handle the same type of situations as require(), but with more complex logic like &lt;code&gt;Nested If Statement&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Handle the same type of situations as require(), but with more complex logic.&lt;/li&gt;
&lt;li&gt;Used abort execution and revert state changes&lt;/li&gt;
&lt;li&gt;Allow you to return an error message.&lt;/li&gt;
&lt;li&gt;Refund any remaining gas to the caller.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CODE EXAMPLE&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Error {
    function errorRevert(uint _i) public pure {
        if (_i &amp;gt; 10)
            revert("Input must be greater than 10");
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Revert is useful when the condition to check is complex. - inputs&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;SUMMARY&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the &lt;strong&gt;&lt;code&gt;require()&lt;/code&gt;&lt;/strong&gt; is used to validate inputs and conditions before execution.&lt;/li&gt;
&lt;li&gt;Use the &lt;strong&gt;&lt;code&gt;revert()&lt;/code&gt;&lt;/strong&gt; is used abort execution and revert state changes&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
