<?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: @CryptoGuideDev - i ❤️ solidity lang + evm</title>
    <description>The latest articles on DEV Community by @CryptoGuideDev - i ❤️ solidity lang + evm (@cryptoguidedev).</description>
    <link>https://dev.to/cryptoguidedev</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%2F968991%2F41bc2ff3-285f-4c43-8fcc-1be977644341.jpg</url>
      <title>DEV Community: @CryptoGuideDev - i ❤️ solidity lang + evm</title>
      <link>https://dev.to/cryptoguidedev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cryptoguidedev"/>
    <language>en</language>
    <item>
      <title>Ethereum Gas Saving Tip: Chose your function names carefully</title>
      <dc:creator>@CryptoGuideDev - i ❤️ solidity lang + evm</dc:creator>
      <pubDate>Tue, 08 Nov 2022 18:31:46 +0000</pubDate>
      <link>https://dev.to/cryptoguidedev/ethereum-gas-saving-tip-chose-your-function-names-carefully-4je5</link>
      <guid>https://dev.to/cryptoguidedev/ethereum-gas-saving-tip-chose-your-function-names-carefully-4je5</guid>
      <description>&lt;h3&gt;
  
  
  Chose your function names carefully in Solidity to save execution gas
&lt;/h3&gt;

&lt;p&gt;Your functions are converted into &lt;a href="https://cryptoguide.dev/post/how-solidity-function-selectors-work/"&gt;function selectors&lt;/a&gt;, which are the first four bytes of a keccak256 hash of the function name.&lt;/p&gt;

&lt;p&gt;When your smart contract is called, Solidity compiles code that checks &lt;em&gt;in order&lt;/em&gt; if you are calling each function selector until it finds it.&lt;/p&gt;

&lt;p&gt;If you have a very commonly used function, make sure its selector has a low value, so it is likely to be the first comparison made.&lt;/p&gt;

&lt;p&gt;The savings are quite minimal (44 gas when 2 functions) and for most smart contracts it isn't a consideration, but it's a really neat trick to get every last bit of gas saving.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;
&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;FunctionSelectorExample&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="cm"&gt;/* 
  This is the mapping of selectors (in order) to the function names
  {
    "706f4c9e": "funcA()", // first - so will be cheapest as itll be the first comparison
    "7092150a": "funcC()"
    "84c5a5ef": "funcB()",  // last - so a bit more expensive as it will be the third comparison
}  */&lt;/span&gt;

  &lt;span class="c1"&gt;// costs 24,364 gas 
&lt;/span&gt;  &lt;span class="c1"&gt;// (cheapest as selector is 706f4c9e, which is first in order)
&lt;/span&gt;  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;funcA&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// costs 24,415 gas
&lt;/span&gt;  &lt;span class="c1"&gt;// (most expensive, as selector is 84c5a5ef, which is third in order)
&lt;/span&gt;  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;funcB&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// costs 24,390 gas
&lt;/span&gt;  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;funcC&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://cryptoguide.dev/posts/solidity-gas-optimizations-guide/"&gt;See more tips on how to save on Ethereum gas here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>ethereum</category>
      <category>evm</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
