Why is my gas cost so high (contract deployment - ERC1155)? Experiences on your contracts?

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 = 2431252. 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, "");
> 
>     }
> 
>     // for now we'll only allow minting of NFT (x1 unique)
> 
>     function addNewArt(bytes memory data) public {
> 
>     _mint(msg.sender, _tokenIdTracker.current(), 1, data);
> 
>     _tokenIdTracker.increment();
> 
>     }
> 
> }
````Preformatted text`


![nft remix sol|690x300](upload://ou2RtFFfZ1rcTT3m9bK9gPivF49.png)

To deploy a contract, a tx is sent to the 0x00 address and the data field is the code to be executed by the EVM (the constructor code). This code must return the bytecode of the actual contract.

In your example calling _mint in the constructor means that the code to mint needs to be present twice, once in the bytes returned as the contract bytecode, and again to be executed by the constructor. This probably increased the deployment cost by a bit.

Try moving that call to it's own method and comparing the size of the deployment bytecode.

Thanks @helio.rosa !

I'll tinker with it today :slight_smile:

@mmm_pinecones , did it make a difference to the total cost?