I am querying a mapping via a web3 call like this:

var Web3 = require('web3'); 
const web3 = new Web3(new Web3.providers.HttpProvider('https://kovan.infura.io/key...'));
var contractABI = new web3.eth.Contract([...abi...], contractAddress);
var orderValue = '15';
contractABI.methods.orders(web3.utils.toHex(orderValue)).call(function(err, result) {
        if (!err) {
        } else {

If orderValue is > 15 then I get the following error:

Error: Couldn't decode bytes32 from ABI: 0x The size doesn't match.

If orderValue is <= 15 (e.g. 10) then I get the following error:

throw new Error('Given parameter bytes has an invalid length: "'+ value + '"');

Error: Given parameter bytes has an invalid length: "0xa"

the mapping in the smart contract looks as follows:

struct Order {
    bytes32 orderId;
    uint32 orderAmount;
mapping(bytes32 => Order) public orders;

If if query orders with Parity I am getting some values back. What am I doing wrong?

  • Try passing 0x0a – Raghav Sood Aug 3 '18 at 14:40
  • 0x0a gives me the same error: Couldn't decode bytes32 from ABI: 0x The size doesn't match. – sunwarri0r Aug 3 '18 at 14:55
  • Just pass orderValue instead of web3.utils.toHex(orderValue). That should clear up the "invalid length" errors. After that, you'll presumably get the "Couldn't decode bytes32 from ABI" error for every orderValue you pass. This is most likely due to the ABI or contract address being wrong. You'd need to share the values you're using for someone to help investigate that. – user19510 Aug 3 '18 at 21:11
  • If I just pass a string e.g. "test", I get: Given parameter is not bytes: "test" – sunwarri0r Aug 4 '18 at 12:01

The answer here is, that the contract was deployed, but empty!

Section 7.1 of the yellow paper it states that "while the initialisation code is executing, the newly created address exists but with no intrinsic body code. For a normal STOP code, or if the code returned is otherwise empty, then the state is left with a zombie account, and any remaining balance will be locked into the account forever" (Thanks to user Thomas Clowes)

The thing that was confusing me was that Parity could do queries on it, even though it returned 0x000 values (web3 didn't return anything but errors). So I thought the contract wasn't empty!


You're giving it bytes, (byte[]), not bytes32. It must be left padded with 0s for the contract to accept it.

Edit: Use fromAscii not toHex

fromAscii is string -> bytes

toHex is anything -> bytes

  • Still the same error: Couldn't decode bytes32 from ABI: 0x The size doesn't match. – sunwarri0r Aug 6 '18 at 7:45
  • Even after left-padding to have a 32 bytes element? – PhABC Aug 7 '18 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.