I'm receiving the result in BN format. How can I convert it into actual string or number? I'm using ethjs library to interact with Smart Contract.
token.totalSupply().then((totalSupply) => {
// result <BN ...> 4500000
});
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI'm receiving the result in BN format. How can I convert it into actual string or number? I'm using ethjs library to interact with Smart Contract.
token.totalSupply().then((totalSupply) => {
// result <BN ...> 4500000
});
Once you have a BN object, you can use .toString()
or .toNumber()
on it.
Per the comments below, your function isn't actually receiving a BN
. It's getting some sort of Results
object that has a single key in it: 0. (Presumably if the function returned multiple values, there would be more keys.)
So first extract the BN
from the Result
:
token.totalSupply().then(result => {
const supply = result[0];
console.log(supply.toString()); // or .toNumber()
});
totalSupply
logs Result { '0': <BN: 100590> }
The total supply must be 1050000.
Mar 30, 2018 at 10:22