3

I'm developing a contract and when I try to test it on Remix, sometimes I can create it, sometimes not.

creation of ContractName errored: transaction execution failed

It seems that the environment requires a huge amount of gas to execute this creation.

Gas Cost

And no matter how I increase the Gas Limit it is never enough.

The funny stuff is that sometimes the very same contract (with no change in its code) can be created without any problem.

There's also a curious fact that when I take a function off that contract it always require a non-infinite amount of gas on its creation:

function Redeem(address account, uint amount) public onlyOwner returns(uint) {
    require(_yield[account] >= amount, "Not enought funds.");

    _yield[account] -= amount;
    return amount;
}

Does anybody has a reasonable explanation for all that. I appreciate very much!


EDIT:

I took some time evaluating the code, and I realized one thing:

There are the contract A and the contract B. A has a function that creates an instance of B.

function AddB(Someinterface x) public onlyOwner {
    require(address(_bs[x.Name()]) == 0x0, "B for this name already exists.");
    require(keccak256(abi.encodePacked(x.Name())) != keccak256(abi.encodePacked("text")), "text name is reserved.");

    _bs[x.Name()] = B(new B(x));
}

When I try to deploy A, I have the problem I told above.
I can always deploy B directly from Remix without any problem.
When I took off the function in A that creates an instance of B, I can deploy A without any problem.
When I keep this function in A, and took off some random functions from B that doesn't seem to have any relation to the problem, A can be deployed normally.
When I keep this function in A, and comment out some random lines in A, A can be deployed normally.

For example:

function _Redeem(address account, uint amount) internal returns(uint) {
    require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");

    amount = _bs[_selectedB[msg.sender]].Redeem(account, amount);
    _totalDeposits += amount;
    _deposits[account] += amount;

    return amount;
}

function _RedeemAll(address account) internal returns(uint) {
    require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");

    uint amount = _bs[_selectedB[msg.sender]].RedeemAll(account);
    _totalDeposits += amount;
    _deposits[account] += amount;

    return amount;
}

This contract is not created.

function _Redeem(address account, uint amount) internal returns(uint) {
    //require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");

    amount = _bs[_selectedB[msg.sender]].Redeem(account, amount);
    _totalDeposits += amount;
    _deposits[account] += amount;

    return amount;
}

function _RedeemAll(address account) internal returns(uint) {
    require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");

    uint amount = _bs[_selectedB[msg.sender]].RedeemAll(account);
    _totalDeposits += amount;
    _deposits[account] += amount;

    return amount;
}

This contract goes ok.

function _Redeem(address account, uint amount) internal returns(uint) {
    require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");

    amount = _bs[_selectedB[msg.sender]].Redeem(account, amount);
    _totalDeposits += amount;
    _deposits[account] += amount;

    return amount;
}

function _RedeemAll(address account) internal returns(uint) {
    //require(address(_bs[_selectedB[msg.sender]]) != 0x0, "This is not redeemable.");

    uint amount = _bs[_selectedB[msg.sender]].RedeemAll(account);
    _totalDeposits += amount;
    _deposits[account] += amount;

    return amount;
}

This also goes ok.

Any thoughts on that?

5
  • 2
    check if constructor arguments are properly set and see if you are doing an infinite looping on the constructor code. smart contract deployment problems are always related to constructor code or to deployment transaction, the rest of the contract code is just checked for syntax. Aug 23, 2018 at 21:51
  • 1
    Don't know why you get errors on deployment, but i think you should return _yield[account] instead of amount in your function. Now it will return the same value as you passed to the function.
    – Maxpeinas
    Aug 23, 2018 at 23:49
  • I removed all the "requires" from the contract A and it worked. Does anybody have an explanation? Aug 24, 2018 at 17:39
  • I'm confused about this notation.. why B twice? B(new B(x));
    – Ossip
    Aug 30, 2018 at 15:36
  • Actually it should be IB(new B(x)); where IB is a Interface and B is a contract, I put everything as B to make it simple. Sep 4, 2018 at 23:34

1 Answer 1

0

After updating Remix and trying to run again I received this error msg:

Contract size error

This make all the sense and it's explained in details here.

Your Answer

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

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