0

I'm working with smart contract development, and using Truffle framework. It was working before, but after adding one more function in my smart contract and it stopped working on migrate.

Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.

I've tried with full gas limit(i.e. 4712388) though issue is persist.

Comment out newly added code, and it starts working again.. any clue?

Edit: Newly added functions(tested on Remix, working fine):

function validateDoc(
    bytes32 _a,
    string _b,    
    uint256 _c
    ) internal view 
    returns(bool, string){

    if(condition 1){
        return(false, "failure message1"); 

    }else if(condition 2){
        return(false, "failure message2"); 
    }
    }else if(condition 3){
        return(false, "failure message3"); 
    }        
    }else if(condition 4){
        return(false, "failure message4"); 
    }        
}

function Main(
    bytes32 _a,
    string _b,
    uint256 _c    
) public returns(bool _success, string _message) {

    (_success, _message) = validateDoc(_a, _b, _c);

    if(_success) {
        // Other code 
        // ...
    }
    return (_success, _message);                
}
1

After reviewing similar issues posted to the Truffle GitHub (such as https://github.com/trufflesuite/truffle/issues/476), it looks like the issue is probably not with the gas amount directly (the error message is somewhat misleading). Instead, the error is most likely a result of the function you added. Can you post the function code please? You most likely made a syntax error in your new function.

  • Code added to the question, it's a minimal example, as full code is large – Hina Khuman Jul 25 '18 at 7:48
  • What version of Truffle are you using? – richardgv Jul 25 '18 at 7:56
  • Truffle v4.1.13 (core: 4.1.13) – Hina Khuman Jul 25 '18 at 7:57
  • What network are you attempting to deploy the contract on (or are you trying to deploy it locally and if so, are you using testrpc or truffle develop)? – richardgv Jul 25 '18 at 8:00
  • Yes, I'm deploying it locally, with private Blockchain – Hina Khuman Jul 25 '18 at 8:03
1

After digging issue in detail, we found that it is because of we have used string messages.

In order to resolve the issue we refactored our smart contract, added enums and returning it from smart contract.

if(condition 1){
    return uint256(Status.MSG1); 

}else if(condition 2){
    return uint256(Status.MSG2);
}
else if(condition 3)){
    return uint256(Status.MSG3);    
}

And handle message string at Nodejs end, perhaps an alternative way to make things works.

Your Answer

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

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