0

I'm encountering a problem related to the gas (I guess).

Please note that I'm using the proxy pattern for upgradeable smart contracts: CODE EXAMPLE HERE - Explanation from Openzeppelin

I'm trying to call the function initialize defined in a logic contract:

/* NOT WORKING EXAMPLE */
function initialize(address superAddress) public {
    require(!_initialized, 'Contract already initialized');
    _ownerAddress = superAddress;
    _ceoAddress = superAddress;
    _cfoAddress = superAddress;
    _cooAddress = superAddress;

    _initialized = true;
}

When I'm calling initialize I'm getting the error: Error: "Returned error: VM Exception while processing transaction: revert"

And this is the related log:

 [08:53:32] eth_sendTransaction
 [08:53:32]   Transaction: 0x7a46396621502cb541f0509ff975fb9695b15d4efd9a5d7c27b320755066a37f
 [08:53:32]   Gas usage: 88988
 [08:53:32]   Block Number: 245
 [08:53:32]   Block Time: Tue Oct 01 2019 08:53:32 GMT+0200 (W. Europe Summer Time)
 [08:53:32]   Runtime Error: revert
 [08:53:32] eth_getBlockByNumber

But, when I'm commenting a couple of assignments in the initialize function (like below) everything is working:

/* WORKING EXAMPLE */
function initialize(address superAddress) public {
    require(!_initialized, 'Contract already initialized');
    _ownerAddress = superAddress;
    _ceoAddress = superAddress;
    /* _cfoAddress = superAddress; */
    /* _cooAddress = superAddress; */

    _initialized = true;
}

Below an example of the call of initialize function on the client side:

contractInst.methods.initialize('0x4F9aA950b153a3D27a4f6ed738f6Ce7D4dc8cA7e').send({})
    .then(resp => console.log(resp))
    .catch(e => console.error(e));

Do you have any clue of the causes of that error? And how to solve it?

Extra notes: I'm using GANACHE and the smart contracts are developed with solidity ^0.5.0;

THANKS!

  • Please share your off-chain code (where you call initialize). The problem is more likely the result of calling this function more than once for the same contract instance. – goodvibration Oct 1 at 9:31
  • Thank you @goodvibration . Regarding the working example, if I call more than once the initialize function I receive the specific error: Error: "Returned error: VM Exception while processing transaction: revert Contract already initialized" because in the require I specified the error message. Soon I'm going to post how I call the initalize function. – Dan Oct 1 at 9:42
  • 1
    You should by the least specify from and gas in the {} parameter that you pass to send. – goodvibration Oct 1 at 10:36
  • It was simply the gas parameter missing! I thought I tried everything :(( Thanks a lot! – Dan Oct 1 at 10:59
  • 1
    You're welcome. – goodvibration Oct 1 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.