0

Please excuse this newbie in advance!

I am wondering if anyone would share their experiences on the cost of deploying a contract, be it in on the main net or on a test net or even remix.

I understand gas costs vary and depend on contract size and amount of computation etc. I am looking for actual experiences from which myself and others reading this post can get a reference point for our own contracts.

I'd also appreciate it if anyone can check my logic here:

Execution cost = based on the amount and size of computational operations of the transaction

Transaction cost = includes execution cost. depends on the size of the contract. Is the base cost (21000 gas) + contract deployment (32000 gas) + cost for ever zero and non-zero byte of data

Gas is based on market prices denominated in Gwei (10^-9 ETH or 0.000000001 ETH)

At the time of this writing, it is about 43 Gwei which is about $2.41 according to Etherscan.

(Sound right?)

I am asking because I have written a short contract on Remix. It's a simple ERC 1155 that I added a function to allow the public to add new tokens (NFT specifically, supply = 1). When I test deploy on remix, it says the tx cost = 8000000 and execution cost = 221309. Which seems extremely high, especially if I follow the logic above. Am I missing something here? Why is it so high? I'm guessing maybe it has to do with importing the OpenZeppelin contract libraries? Any help or guidance would be appreciated. Here is the code and snapshot of gas cost below.

> pragma solidity >=0.8.0 <0.9.0;
> 
> import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; 
> import "@openzeppelin/utils/Counters.sol"; 
> 
> contract ScratchCollective is ERC1155 {
>     using Counters for Counters.Counter;
> 
>     uint256 public constant ICHIBAN = 0;
> 
>     Counters.Counter private _tokenIdTracker;
> 
>     constructor() ERC1155("https://thebourneoldtomato.github.io/data/test{id}.json") {
>         _mint(msg.sender, ICHIBAN, 1, "");
>     }
> 
>     // allow user or client to create NFT
>     function addNewArt(bytes memory data) public {
>     _mint(msg.sender, _tokenIdTracker.current(), 1, data);
>     _tokenIdTracker.increment();
>     } 
>  }

enter image description here

1 Answer 1

0

Deep down, it's the sum of OPCODES executed to run the transaction.

That consists of parsing the input, including the bytecode payload and running the constructor which itself contains more work to do on top of deploying the bytecode to the generated address.

It's really quite a lot to estimate it by any other means than 1) try and 2) find out.

Fortunately, there are plenty of tools to help you do that without committing and you can use your intuition to pinpoint trouble - contract size, expensive constructor, etc.

Since you are using Remix, deploy the contract within the Remix VM and explore the deployment transaction. The transaction cost in gas is revealed for you. That, together with a reasonable, current gasPrice estimate (e.g. ethGasStation.info) will give you a good estimate. Eth Cost = gasUsed x gasPrice. $ Cost = Eth Cost * ETH:USD.

Hope it helps.

1
  • Guess there isn't much to do but tinker with it at this point :) Thanks Rob!
    – notaquant
    Commented Aug 22, 2021 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.