Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the gas cost strangely so big when deploy. #15061

Closed
anthhub opened this issue Apr 26, 2024 · 2 comments
Closed

Why the gas cost strangely so big when deploy. #15061

anthhub opened this issue Apr 26, 2024 · 2 comments
Labels

Comments

@anthhub
Copy link

anthhub commented Apr 26, 2024

Description

Why deploy the code failed. The error log is as following:

gas	1000000000000000000 gas
transaction cost	984375000000005328 gas 
execution cost	984374999999815072 gas 

revert
	The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
You may want to cautiously increase the gas limit if the transaction went out of gas.

why the gas cost so big?

pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Uniswap {
    string[] public tokens = ["CoinA", "CoinB", "CoinC"];
    mapping(string => ERC20) public tokenInstanceMap;
    uint256 ethValue = 100000000000000;

    constructor() {
        for (uint i=0; i<tokens.length; i++) {
            CustomToken token = new CustomToken(tokens[i], tokens[i]);
            tokenInstanceMap[tokens[i]] = token;
        }
    }
}

contract CustomToken is ERC20 {
    constructor(string memory name, string memory symbol) ERC20(name, symbol) {
        _mint(msg.sender, 1000 * 10 ** 18);
    }
}

-->

@DS-Coding0
Copy link

I have the same problem, it look's like the constructor part take much gas.. but i don't find any solution at this moment.

@mehtavishwa30
Copy link
Contributor

Hey @anthhub!

The gas cost might be high because of the large bytecode which is due to the fact that the contract is using new to deploy another contract. Using new means that the compiler needs to include a copy of the contract to be deployed inside the one that is deploying it. This can easily make a contract blow up in size.

However, this is not a bug and hence, I will be closing the issue. I suggest that instead of opening issues for ad-hoc Solidity support questions like this, you consider checking out the [Ethereum StackExchange](https://ethereum.stackexchange.com/ https://soliditylang.org/) for that purpose.

@mehtavishwa30 mehtavishwa30 closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants