0

I want to track an event emitted by the smart contract from the backend using web3.js, But the Problem is there is the array type(uint8[]) in the event ,whenever I try to decode it it gives the Overflow error

This is the event I want to track: event NFTSold(uint8[] indexed saleId, uint256 totalPrice, address buyer); This is the code I have written for decoding the events

var value = web3.eth.abi.encodeEventSignature(
  "NFTSold(uint8[],uint256,address)"
);
console.log("value--->",value);
web3.eth
  .subscribe("logs", {
    address: Marketplaceinstance._address.toString(),//address of the contract which we want listen events to
    topics: [value],
  })
  .on("data", async (events) => {
    console.log("cameuntilhere");
    const typesArray = [
      { type: "uint8[]", name: "saleId",indexed: true},//if its indexed parameter we need to mark indexed as true
      { type: "uint256", name: "totalPrice"},
      { type: "address", name: "buyer" },
    ];
    console.log("typesArray--->",typesArray);
    let topiclength = events.topics.length;
    console.log("topicLength---->",topiclength);
    let result = web3.eth.abi.decodeLog(
      typesArray,
      events.data,
      events.topics.slice(1, topiclength)
    );

    console.log("result---->",result);
    //here we are getting from ,to and value from the event emited
    console.log(`
    saleId:${result.saleId}
    totalPrice:${result.totalPrice}
    buyer:${result.buyer}
   `);


  });

And This is the error I am getting

Error: overflow [ See: https://links.ethers.org/v5-errors-NUMERIC_FAULT-overflow ] (fault="overflow", operation="toNumber", value="22581645139872629890233439717971975110198959689450188087151966948260709403752", code=NUMERIC_FAULT, version=bignumber/5.7.0)     
    at Logger.makeError (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\logger\lib\index.js:238:21)
    at Logger.throwError (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\logger\lib\index.js:247:20)
    at throwFault (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\bignumber\lib\bignumber.js:303:19)
    at BigNumber.toNumber (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\bignumber\lib\bignumber.js:151:13)
    at C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\abi\lib\coders\array.js:92:60
    at Array.forEach (<anonymous>)
    at unpack (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\abi\lib\coders\array.js:88:12)
    at TupleCoder.decode (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\abi\lib\coders\tuple.js:74:60)
    at AbiCoder.decode (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\@ethersproject\abi\lib\abi-coder.js:98:22)
    at ABICoder.decodeParametersWith (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\web3-eth-abi\lib\index.js:310:30)
    at ABICoder.decodeParameters (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\web3-eth-abi\lib\index.js:291:17)
    at ABICoder.decodeParameter (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\web3-eth-abi\lib\index.js:280:17)
    at C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\web3-eth-abi\lib\index.js:348:25     
    at Array.forEach (<anonymous>)
    at ABICoder.decodeLog (C:\Users\Nalgesh\Documents\Natsoft\Web3ScriptsForGettingSaleIdandTokenId\node_modules\web3-eth-abi\lib\index.js:344:12)
    at Subscription.<anonymous> (file:///C:/Users/Nalgesh/Documents/Natsoft/Web3ScriptsForGettingSaleIdandTokenId/buyNFT.js:26:31) {
  reason: 'overflow',
  code: 'NUMERIC_FAULT',
  fault: 'overflow',
  operation: 'toNumber',
  value: '22581645139872629890233439717971975110198959689450188087151966948260709403752'
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.