1

I want to printthe value of iVar:

pragma solidity ^0.5.1;
   contract PRetVal {
      uint8  iVar =0;
      function testFunc() public returns (uint8) {
         iVar = iVar + 10;
         return iVar;
      }
   }

I am trying the following :

truffle(development)> PR = await PRetVal.at(0x596D30c26211B4Dab998F63D6Bf5eba55B0B1d2D) 
undefined
truffle(development)> await PR.getIVar 
undefined truffle(development)>

But I am not getting any value. Somebody please guide me.

Zulfi.

1 Answer 1

3

You need a couple of changes to see the value of iVar:

  1. Make it public in order to generate a getter function:

    uint8 public iVar = 0;

  1. Call the variable with parenthesis (because it is now public and has a getter):

    truffle(development)> await PR.getIVar()

Alternatively, you could also add a function in the contract to retrieve the value, such as:

function getiVar() external view returns(uint8){
    return iVar;
}
2
  • I am getting > PR.getiVar() <BN: a> what is the meaning of BN?
    – zak100
    Feb 7, 2021 at 4:40
  • 1
    This is 'Big Number' type, so you can do a conversion such as : PR.iVar().then(result => console.log(result.toNumber())) Feb 7, 2021 at 6:43

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.