When calling a function on a smart contract that takes a tokenID, I pass in the tokenID into web3 - but web3 then parses that string into another value it seems, pads it to the left with a ton of zeros and then the contract call fails.

tokenID: "5347359381416754638292106073567748474581852345025787828513953871505554409252111"

export async function getTokenURI(address, tokenID) {
  try {
    console.log(address, typeof tokenID);
    return await getterContract(ABI, address, "tokenURI", [tokenID]);
  } catch (err) {
    console.log(address, typeof tokenID);
    return "";
export const getterContract = async (ABI, address, methodName, params) => {
  try {
    const contractInstance = await getDeployedContract(ABI, address);

    return await contractInstance.methods[methodName](...params)
      .then((res) => {
        return res;
  } catch (e) {
    throw e;

Calling getTokenURI and passing in the token ID above - the actual value web3 is sending to the contract is: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005347359381416754638292106073567748474581852345025787828513953871505554409252111

Instead of the correct value of 5347359381416754638292106073567748474581852345025787828513953871505554409252111

When passing in a smaller value such as 123456 it works fine.

Both values are passed into the function as strings - so not sure why the length of the string matters?

It seems to be converted or something since its padded to the left with a ton of zeros.

How to fix this?

  • What's the function signature in solidity? What's tokenID javascript type? – Ismael Jan 19 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.