Yes, the BigNumber / BigInt thing is a bit of a pain, particularly when dealing with async results, as one often has to with Ethers.js. e.g. const supply = (await contract.totalSupply()).toBigInt(). It's pretty tedious.
I suggest either converting to BigInt early (for more modern JS) in the rest of the code, or to mostly ignore BigInt and just stick with BigNumber, like some dev from 2 years ago lol.
Adapting your example above to first approach:
const result = value1.toBigInt() + value2.toBigInt();
console.log(result);
Fortunately, Ethers.js now considers BigInt to be "BigNumberIsh", so it accepts BigInts as arguments for uint etc.
First snippet there could also be done as: const supply = await contract.totalSupply().then(BigInt)
or const supply = BigInt(await contract.totalSupply()).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yes, the BigNumber / BigInt thing is a bit of a pain, particularly when dealing with async results, as one often has to with Ethers.js. e.g.
const supply = (await contract.totalSupply()).toBigInt()
. It's pretty tedious.I suggest either converting to BigInt early (for more modern JS) in the rest of the code, or to mostly ignore BigInt and just stick with BigNumber, like some dev from 2 years ago lol.
Adapting your example above to first approach:
Fortunately, Ethers.js now considers BigInt to be "BigNumberIsh", so it accepts BigInts as arguments for
uint
etc.First snippet there could also be done as:
const supply = await contract.totalSupply().then(BigInt)
or
const supply = BigInt(await contract.totalSupply())
.