I have a simple contract Foo which is deployed to a Ganache network.
pragma solidity ^0.4.18;
contract Foo {
uint storageData;
function set(uint x) public {
storageData = x;
}
function get() constant public returns (uint) {
return storageData;
}
}
Now when I want to interact with it using truffle console, first I set the value
truffle(development)> Foo.at("0x4d4337B075a442cF3351Fa11c425C350cE2984F5").set(123)
Question 1: Then I tried to retrieve that value but it is returning a BignNumber. Why is it not an integer?
truffle(development)> Foo.at("0x4d4337B075a442cF3351Fa11c425C350cE2984F5").get.call()
BigNumber { s: 1, e: 0, c: [ 123 ] }
Question 2: How can you convert it to an integer or string?
truffle(development)> Foo.at("0x4d4337B075a442cF3351Fa11c425C350cE2984F5").get.call().toNumber()
TypeError: Foo.at(...).get.call(...).toNumber is not a function
Tried to console.log it after a .toNumber, it prints out the right value 123, but why is it printing an undefined too?
truffle(development)> Foo.at("0x4d4337B075a442cF3351Fa11c425C350cE2984F5").get.call().then(a => console.log(a.toNumber()))
123
undefined
toNumber()function:count = await app.getCount; count.toNumber()– Justin Apr 10 '19 at 09:30