TransWikia.com

Acceptable Gas Usage of Smart Contract functions

Ethereum Asked by wbt_ on December 30, 2021

So I’ve been building a smart contract where users can register and store their projects at. I’m wondering if the gas usage of functions within my contract is acceptable or not ( I’m new to solidity 🙂 ).

Here’s the current Gas Cost of my Smart Contract functions:

  • Registration: 92k+ Gas
  • Project Creation: 177k+ Gas

Is there a tool (like eth gas station) that shows real-time Gas usage per contract function call?

3 Answers

Perhaps you might wanna share your code with us so we can see if 92k for Registration and 177k for Project Creation whether it is worth. It all depends on what kind of logic you need to happen, the more code and state changes you add the higher the gas price will be.

However I wrote article where I compare the gas price when dealing with some basic logic like working with strings, arrays, conditions and so on. You can check it out here - https://www.linkedin.com/pulse/solidity-smart-contracts-how-gas-greedy-miroslav-nedelchev/

Answered by Miroslav Nedelchev on December 30, 2021

I don't think there are standards about gas-usage of functions, and it wouldn't make sense, except for maybe functions part of standards like ERC20 or ERC773.

Without code, it's hard to tell if it's acceptable or not. It's up to you to try to minimise the writing from zero to non-zero in storage, which is expensive, try to reduce the use of expensive operations, etc...

Answered by Elisha Drion on December 30, 2021

You can use Remix to test that: http://remix.ethereum.org/

Just paste your contract in place of the default one you will see. Your contract will be compiled automatically. On the right side choose "Run" tab, then choose JavaScript VM for environment and deploy your contract with "Create" button. Buttons allowing to interact with your contract's functions will apear below.

Trigger the function you want to test and in the middle section of the page, at the bottom, you will see info if your transaction succeeded and two buttons: "Details" and "Debug". Click "Details" and there you will find what was the gas cost of your transaction.

Image below shows how to find this window with "Details" and "Debug" if it is not visible by default.

enter image description here

Answered by Mike A. Clearance on December 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP