Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ Released with 1.0.0-beta.37 code base.
- Updated README to include Webpack 5 create-react-app support instructions (#4173)
- Update the documentation for `methods.myMethod.estimateGas` (#4702)
- Fix typos in REVIEW.md and TESTING.md (#4691)
- Fix encoding for "0x" string values (#4512)


### Changed
Expand Down
7 changes: 6 additions & 1 deletion packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ ABICoder.prototype.decodeParametersWith = function (outputs, bytes, loose) {

outputs.forEach(function (output, i) {
var decodedValue = res[returnValue.__length__];
decodedValue = (decodedValue === '0x') ? null : decodedValue;

const isStringObject = typeof output === 'object' && output.type && output.type === 'string';
const isStringType = typeof output === 'string' && output === 'string';

// only convert `0x` to null if it's not string value
decodedValue = (decodedValue === '0x' && !isStringObject && !isStringType) ? null : decodedValue;

returnValue[i] = decodedValue;

Expand Down
6 changes: 6 additions & 0 deletions packages/web3-eth-abi/types/tests/abi-coder-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ abiCoder.decodeParameter(
0000000000000000000000004e`
);

// $ExpectType { [key: string]: any; }
abiCoder.decodeParameter(
'string',
'0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000023078000000000000000000000000000000000000000000000000000000000000'
);

// $ExpectError
abiCoder.decodeParameter('uint256', [345]);
// $ExpectError
Expand Down
3 changes: 3 additions & 0 deletions test/abi.decodeParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ describe('lib/solidity/coder', function () {
'0000000000000000000000000000000000000000000000000000000000000060' +
'0000000000000000000000000000000000000000000000000000000000000006' +
'737472696e670000000000000000000000000000000000000000000000000000'})

test( { types: ['string'], expected: ["0x"],
values: '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000023078000000000000000000000000000000000000000000000000000000000000'})
});
});

Expand Down