0

We have a function as follows:

function newObject(bytes32 _id, uint256 number_of_sub_states, bytes32[10] sub_states_types, bytes32[10] sub_states_values, address _owner) public returns(bool success) {
        require(!isObject(_id));

        uint256 counter=0;
        for(counter; counter < number_of_sub_states; counter++) {

            objectStructs[_id].state.sub_state[sub_states_types[counter]] = sub_states_values[counter];

            emit LogNewObject(msg.sender, _id, bytes32(sub_states_types[counter]), bytes32(sub_states_values[counter]), _owner);

        }

        objectStructs[_id].owner = _owner;
        objectStructs[_id].isObject = true;

        objectList.push(_id);

        return true;
    }

I can invoke this function in remix successfully as folloaws :

40,3,["location","price","sold","","","","","","",""],["Paris","50","No","","","","","","",""], 0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773 

But when I invoke this function with web3 as follows :

contractInstance.methods.newObject("40","3",["location","price","sold","","","","","","",""],["Paris","50","No","","","","","","",""], '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773').send({ from: '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773' }, function(error, result) {
    console.log(error);
    console.log(result)
});

I receive following error :

Error: Given parameter is not bytes: "40"
    at SolidityTypeBytes.formatInputBytes [as _inputFormatter] (/home/s/node_modules/web3-eth-abi/src/formatters.js:56:15)
    at SolidityTypeBytes.SolidityType.encode (/home/s/node_modules/web3-eth-abi/src/type.js:188:17)
    at /home/s/node_modules/web3-eth-abi/src/index.js:255:29
    at Array.map (<anonymous>)
    at ABICoder.encodeParameters (/home/s/node_modules/web3-eth-abi/src/index.js:254:34)
    at /home/s/node_modules/web3-eth-contract/src/index.js:420:24
    at Array.map (<anonymous>)
    at Object._encodeMethodABI (/home/s/node_modules/web3-eth-contract/src/index.js:419:12)
    at Object._processExecuteArguments (/home/s/node_modules/web3-eth-contract/src/index.js:735:39)
    at Object._executeMethod (/home/s/node_modules/web3-eth-contract/src/index.js:760:54)
> 

Also, I tried following according to comment of user goodvibration :

> contractInstance.methods.newObject(0x28,0x3,["location","price","sold","","","","","","",""],["Paris","50","No","","","","","","",""], '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773').send({ from: '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773' }, function(error, result) {
...     console.log(error);
...     console.log(result)
... });
Error: Given parameter is not bytes: "40"
    at SolidityTypeBytes.formatInputBytes [as _inputFormatter] (/home/s/node_modules/web3-eth-abi/src/formatters.js:56:15)
    at SolidityTypeBytes.SolidityType.encode (/home/s/node_modules/web3-eth-abi/src/type.js:188:17)
    at /home/s/node_modules/web3-eth-abi/src/index.js:255:29
    at Array.map (<anonymous>)
    at ABICoder.encodeParameters (/home/s/node_modules/web3-eth-abi/src/index.js:254:34)
    at /home/s/node_modules/web3-eth-contract/src/index.js:420:24
    at Array.map (<anonymous>)
    at Object._encodeMethodABI (/home/s/node_modules/web3-eth-contract/src/index.js:419:12)
    at Object._processExecuteArguments (/home/s/node_modules/web3-eth-contract/src/index.js:735:39)
    at Object._executeMethod (/home/s/node_modules/web3-eth-contract/src/index.js:760:54)

However, I receive same error.

What is the reason ? and how can I fix this ?

  • Try "0x28" instead... – goodvibration May 6 '18 at 16:20
  • @goodvibration Thank you. I tried it however i receive same error! I explained it in my question. It seems strange ! – Questioner May 6 '18 at 17:09
1

I invoked this function as follows and it works :

contractInstance.methods.newObject(web3.utils.asciiToHex("50"),web3.utils.asciiToHex("3"),[web3.utils.asciiToHex("location"),web3.utils.asciiToHex("price"),web3.utils.asciiToHex("sold"),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex("")],[web3.utils.asciiToHex("Paris"),web3.utils.asciiToHex("50"),web3.utils.asciiToHex("No"),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex(""),web3.utils.asciiToHex("")], '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773').send({ from: '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773' }, function(error, result) {
    console.log(error);
    console.log(result)
});

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.