This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
when a string param is empty in data then decodeLog throws "The parameter "0x" must be a valid HEX string." #1044
Closed
Description
web3@1.0.0-beta.20
It seems web3.eth.abi.decodeLog
doesn't handle cases when a string data in event log is empty, it throws:
Uncaught Error: The parameter "0x" must be a valid HEX string.
at Object.hexToUtf8 (utils.js:186)
at SolidityTypeString.formatOutputString [as _outputFormatter] (formatters.js:209)
at type.js:246
at SolidityTypeString../node_modules/web3/packages/web3-eth-abi/src/types/type.js.SolidityType.decode (type.js:247)
at index.js:322
at Array.forEach (<anonymous>)
at ABICoder../node_modules/web3/packages/web3-eth-abi/src/index.js.ABICoder.decodeParameters (index.js:321)
at ABICoder../node_modules/web3/packages/web3-eth-abi/src/index.js.ABICoder.decodeLog (index.js:363)
at abi-decoder.js:181
at Array.map (<anonymous>)
at Object.decodeLogs (abi-decoder.js:119)
at XMLHttpRequest.xhr.onreadystatechange (ethHelper.js:150)
To reproduce, based on
Tx1 (param "narrative" is "test x" in data) and Tx2 (param "narrative" is "" in data)
let _inputs = [
{ indexed: true, name: "from", type: "address" },
{ indexed: true, name: "to", type: "address" },
{ indexed: false, name: "amount", type: "uint256" },
{ indexed: false, name: "narrative", type: "string" }
];
let _topics = [
"0x000000000000000000000000ae653250b4220835050b75d3bc91433246903a95",
"0x00000000000000000000000094011c67bc1e6448ed4b8682047358ca6cd09470"
];
let _logDataTx1 =
"0x0000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000067465737420780000000000000000000000000000000000000000000000000000";
let _logDataTx2 =
"0x000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000";
let _decodedDataTx1 = web3.eth.abi.decodeLog(
_inputs,
_logDataTx1,
_topics
);
console.log("Decoded data Tx1:", _decodedDataTx1);
// ^^^^ output is correct, last param is there ^^^^
let _decodedDataTx2 = web3.eth.abi.decodeLog(
_inputs,
_logDataTx2,
_topics
);
// ^^^^ Throws: Uncaught Error: The parameter "0x" must be a valid HEX string. ^^^^
console.log("Decoded data Tx2:", _decodedDataTx2);