---
title: "Discussion on \"How To Save Gas When Writing Your Smart Contract In Solidity?\" | Hashnode"
description: "Discussion on \"How To Save Gas When Writing Your Smart Contract In Solidity?\". Save gas when writing your smart contract in solidity. Tips when writing solidity code."
url: "https://hashnode.com/posts/how-to-save-gas-when-writing-your-smart-contract-in-solidity/62fb6aedc0004ed752ad968c"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How To Save Gas When Writing Your Smart Contract In Solidity?](https://techblog.geekyants.com/how-to-save-gas-when-writing-your-smart-contract-in-solidity?utm_source=hashnode&utm_medium=feed)

Save gas when writing your smart contract in solidity. Tips when writing solidity code.

Aug 16, 2022 · 5 min read · techblog.geekyants.com  
Updated Mar 29, 2023  
Read the article

-   [#solidity](https://hashnode.com/tag/solidity)
-   [#web3](https://hashnode.com/tag/web3)
-   [#web30](https://hashnode.com/tag/web30)
-   [#blockchain](https://hashnode.com/tag/blockchain)

## Written by

[Tarun Soni](https://hashnode.com/@tarunsoni12)

@tarunsoni12 · India

  
[View profile](https://hashnode.com/@tarunsoni12)

I build and break stuff, Everything Frontend, web3

Everything JS Frontend, mobile and web3

## Responses 2

Markdown supported · ⌘↵ to post

[bruce doctor](https://hashnode.com/@bruce836)

[Aug 8, 2023](https://hashnode.com/posts/how-to-save-gas-when-writing-your-smart-contract-in-solidity/62fb6aedc0004ed752ad968c/comment/64d250c632895e0c90ef627d)

impressive article. how do you calculate or generate the gas usage table ?

[Tarun Soni](https://hashnode.com/@tarunsoni12)

[Sep 23, 2023](https://hashnode.com/posts/how-to-save-gas-when-writing-your-smart-contract-in-solidity/62fb6aedc0004ed752ad968c/comment/64d250c632895e0c90ef627d#reply-650f50e866a8e03eff7a3c3c)

Hey Bruce, Glad you liked the article. I pasted the code in [remix.ethereum.org](https://remix.ethereum.org/) and we can see the gas consumed at the bottom

[Nitish Srivastava](https://hashnode.com/@nitishcolossalbit)

[Mar 22, 2023](https://hashnode.com/posts/how-to-save-gas-when-writing-your-smart-contract-in-solidity/62fb6aedc0004ed752ad968c/comment/641ad421a581f3121e293f7c)

man in your first point, in table you are showing function1 gas consumption is less then function2 , then how function2 is cheaper than function one. more gas consumption , more cost ... isn't?

[Tarun Soni](https://hashnode.com/@tarunsoni12)

[Mar 29, 2023](https://hashnode.com/posts/how-to-save-gas-when-writing-your-smart-contract-in-solidity/62fb6aedc0004ed752ad968c/comment/641ad421a581f3121e293f7c#reply-64246c208ec0c0a265b0ae7e)

Thanks [Nitish Srivastava](https://hashnode.com/@nitishcolossalbit) Yes, the testFunction2() consumed less gas, I've updated the table. :)
