diff --git a/packages/cli/src/commands/decode.ts b/packages/cli/src/commands/decode.ts index c78431e4c..6e33b406d 100644 --- a/packages/cli/src/commands/decode.ts +++ b/packages/cli/src/commands/decode.ts @@ -93,9 +93,9 @@ export async function decode({ renderArgs( { ...components[i], - name: `[${i}]`, + name: `${components[i].name}`, }, - v[i], + v[`${components[i].name}`] ? v[`${components[i].name}`] : v[i], offset.repeat(2) ); } @@ -148,14 +148,21 @@ function _renderValue(type: viem.AbiParameter, value: string | bigint) { return value.toString(); case type.type === 'address': - return viem.getAddress(value); - + return viem.getAddress(value as string); case type.type == 'bool': return typeof value == 'string' && value.startsWith('0x') ? viem.hexToBool(value as viem.Hex) : value; case type.type.startsWith('bytes'): try { - return viem.hexToString(value as viem.Hex, { size: 32 }); + const decodedBytes32 = viem.hexToString(value as viem.Hex, { size: 32 }); + + // Check for characters outside the ASCII range (0-127) + // in case the bytes32 value isnt meant to be converted (e.g an identifier) + if (/[\u0080-\uFFFF]/.test(decodedBytes32)) { + return `${value}`; + } + + return decodedBytes32; } catch (err) { const settings = resolveCliSettings(); if (settings.trace) { @@ -183,7 +190,6 @@ function _parseData(abis: ContractData['abi'][], data: viem.Hash[]) { data: data.length > 1 ? data[data.length - 1] : '0x', }) ); - if (result) return { abi, result }; }