1

Testing a small piece of code that gets information and the current block, as follows:

pragma solidity ^0.4.16;

contract BlockInvestigator {
    address public minerAddress;
    uint public gasPrice;
    uint public balance;
    uint public blockNum;

    function getMiner() payable {
        blockNum = block.number;
        minerAddress = block.coinbase;
        gasPrice = tx.gasprice;
        balance = minerAddress.balance;
    }
}

I'm trying to update the state variables of the contract everytime I call getMiner. However, after deploying the contract and calling getMiner() through a transaction, the state variables do not change (they are all zero from initialization).

Am I doing something wrong, or this a bug?

EDIT: This code works when I remove the variables balance and blockNum and their assignments within getMiner().

  • 1
    How much gas are you providing in your transaction? Try increasing it since this sounds like an Out of Gas exception. – eth Oct 5 '17 at 6:03
  • Do you know how to increase gas when calling from the console? E.g. calling in the console myInstance.getMiner() ? Can't seem to find any literature on it. @eth – jojeyh Oct 5 '17 at 18:12
  • @eth Nvm got it and it was an Out of Gas exception, thanks – jojeyh Oct 5 '17 at 18:24
  • Good you got it :) Perhaps you can post your own answer to help others who may stumble on your question. – eth Oct 10 '17 at 8:43

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.