0

I am working with a private blockchain, and am having a problem where simple functions and constructors simply fail to work. For instance:

    constructor(address admin) public{

        owner = msg.sender;
        valid_admins[admin] = true;
        valid_admins[msg.sender] = true; // so the deployer can be admin too.
        max_score = 5;
        min_score = -5;
        lecture_tokens = 5;
    }

I deployed this, but calling the relevant functions, lecture_tokens, max_score and min_score are all zero, owner is 0x000...000, and calling valid_admins on the owner returns false.

lecture_tokens, max_score and min_score are all zero

owner is 0x0000000000000000000000000000000000000000

The <code>valid_admins</code> returns <code>false</code> for the address entered in the constructor call

It seems like everything is returning with zeroes, false, etc - whatever the initial value is for the type. Even this:

    function f1() public pure returns(uint) {
        return(10);
    }
  • returns zero:

A function that consists only of return(10) returns 0

Does anyone have any idea of what could cause this? Here is the genesis block I used to initialise my blockchain:

{
    "config": {
        "chainId":123 ,
        "homesteadBlock": 0,
        "byzantiumBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },

    "nonce": "0x0000000000000042",     "timestamp": "0x0",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x00",     "gasLimit": "0x8000000",     "difficulty": "0x80",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0xb4a06c62c487b418129b816e41890060d0749787",
    "alloc":{
      "b4a06c62c487b418129b816e41890060d0749787":{
        "balance":"6660010005550000100777"
      }
  }
}
  • Can you check if the contract was deployed correctly? – Ismael Sep 9 at 1:09
  • @Ismael Well, it was confirmed as deployed in MetaMask. But given that it doesn't seem to have set any of the variables like the constructor said it was supposed to, I wouldn't exactly say 'correctly'. – Dave Cochran Sep 9 at 1:38
  • It appears you do not have constantinople/petersburg opcodes enabled in you private network, if you are using solc v0.5 it might be the cause. See this how to enable them ethereum.stackexchange.com/questions/67794/…. – Ismael Sep 9 at 13:53
  • This should not even compile. You are using msg.sender in your constructor. For that to work you need to mark your constructor as payable. – Iftifar Taz Sep 15 at 4:39

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.