How can I use ethers.js to get the token id (34797) from this 0x number?
0x0000000000000000000000000000000000000000000000000000000000034797
I'm not sure which util to use from ethers.js I've looked through the docs and Googled it.
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 communityUse BigNumber
hexText = "0x0000000000000000000000000000000000000000000000000000000000034797"
numb = new ethers.utils.BigNumber(hexText).toNumber()
console.log(numb)
No need for ethers.js, you just need to convert it from hexadecimal to decimal:
parseInt('0x34797',16)
214935
(which is different than 34797).
const { BigNumber } = require('ethers').utils;
const hexString = "0x0000000000000000000000000000000000000000000000000000000000034797";
const bigNumber = BigNumber.fromHexString(hexString);
const tokenId = bigNumber.toString();
console.log(tokenId); // "34797"