0

I'm trying to retrieve a public variable from a contract:

pragma solidity ^0.4.4;

contract Test_Uint {
    uint public something;

    function Test_Uint() {
        something = 42;
    }
}

Note the hard-coded value 42. Here is the test code in truffle:

var thing = artifacts.require("./Test_Uint.sol");

contract('Test_Uint', function(accounts) {

  it("should provide access to something", function() {

    thing.deployed().then(function(instance) {

      instance.something.call().then(function(res) {
          console.log(res);
      });    
    });
  });
});

I was hoping for 42 or even "42", but it always prints:

{ [String: '42'] s: 1, e: 1, c: [ 42 ] }

What is the right way to access the value?

1

The result is a BigNumber object. You probably want to do:

console.log(res.toString())

See more on this in the BigNumber docs.

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.