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) {
callback(result);
} else {
callback(err);
}
});
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?
0x0a
gives me the same error:Couldn't decode bytes32 from ABI: 0x The size doesn't match.
– sunwarri0r Aug 3 '18 at 14:55orderValue
instead ofweb3.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 everyorderValue
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:11string
e.g. "test", I get:Given parameter is not bytes: "test"
– sunwarri0r Aug 4 '18 at 12:01