Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,7 @@ Released with 1.0.0-beta.37 code base.
## [Unreleased]

## [1.2.10]

### Fixed

- Extend `_txInputFormatter` with hex prefix check (#3317)
4 changes: 4 additions & 0 deletions packages/web3-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ var _txInputFormatter = function (options) {
delete options.input;
}

if (options.data && !options.data.startsWith('0x')) {
options.data = '0x' + options.data;
}

if (options.data && !utils.isHex(options.data)) {
throw new Error('The data field must be HEX encoded data.');
}
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-eth-contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ Contract.prototype._encodeMethodABI = function _encodeMethodABI() {
if(!this._deployData)
throw new Error('The contract has no contract data option set. This is necessary to append the constructor parameters.');

if(!this._deployData.startsWith('0x')) {
this._deployData = '0x' + this._deployData;
}

return this._deployData + paramsABI;

}
Expand Down
15 changes: 15 additions & 0 deletions test/formatters.inputTransactionFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ var tests = [{
gas: '0x3e8',
gasPrice: '0x3e8'
}
}, {
input: {
data: '34234bf23bf4234',
value: '100',
from: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS',
gas: '1000',
gasPrice: '1000'
},
result: {
data: '0x34234bf23bf4234',
value: '0x64',
from: '0x00c5496aee77c1ba1f0854206a26dda82a81d6d8',
gas: '0x3e8',
gasPrice: '0x3e8'
}
}];

describe('formatters', function () {
Expand Down