1

I have a counter in a Solidity contract:

uint8 public transactionCounter;
function ContractConstructor() public {
    transactionCounter = 0;
}

function getTransactionCounter() returns (uint8) {
    return transactionCounter;
}

function trns() {
    transactionCounter += 1;
}

When interacting with the contract, i get back the transactionCounter

App.contract.XYContract.deployed()then(function(instance){
    return instance.getTransactionCounter.call();
}).then(function(counter) {
    console.log(counter);
});

In the JavaScript console, I get:

e {s: 1, e: 0, c: Array(1)}

What are s, e and c and where is it documented?

WBT
  • 565
  • 1
  • 5
  • 16
TMOTTM
  • 1,953
  • 2
  • 14
  • 23

1 Answers1

2

If the return value of a call is a number, you'll get back a BigNumber. You can use counter.toString() or counter.toNumber() (though note that the latter may lose precision on large numbers, which is why BigNumber exists in the first place).

Read more in the web3.js documentation.

user19510
  • 27,999
  • 2
  • 30
  • 48
  • Or is it a transaction result: http://truffleframework.com/docs/getting_started/contracts#processing-transaction-results – TMOTTM Jan 17 '18 at 20:52
  • You didn't make a transaction, so no, it's not a transaction result. (You could easily verify what I told you by calling .toString() on it.) – user19510 Jan 17 '18 at 21:27
  • I did .toString() it, it gave me [Object object] on the console. – TMOTTM Jan 17 '18 at 22:24
  • I suppose it's possible Truffle is doing something weird? web3.js itself returns BigNumber objects when the return value is numeric, and what you pasted certainly looks like one. – user19510 Jan 17 '18 at 22:37
  • I just noticed that the code you pasted isn't syntactically correct. Maybe share the actual code you're using (including the .toString)? – user19510 Jan 17 '18 at 22:39
  • Ok... which part? Its a copy but i‘ll check again – TMOTTM Jan 18 '18 at 18:12