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?

0

1 Answer 1

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.

6
  • Or is it a transaction result: truffleframework.com/docs/getting_started/…
    – TMOTTM
    Commented Jan 17, 2018 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
    Commented Jan 17, 2018 at 21:27
  • I did .toString() it, it gave me [Object object] on the console.
    – TMOTTM
    Commented Jan 17, 2018 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
    Commented Jan 17, 2018 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
    Commented Jan 17, 2018 at 22:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.