Problem beim Aufrufen einer Funktion mit Byte32-Parameter: "Angegebener Parameter ist kein Byte"?

Wir haben eine Funktion wie folgt:

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;
    }

Ich kann diese Funktion in Remix erfolgreich wie folgt aufrufen:

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

Aber wenn ich diese Funktion mit web3 wie folgt aufrufe:

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

Ich erhalte folgenden Fehler:

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)
> 

Außerdem habe ich gemäß dem Kommentar des Benutzers goodvibration Folgendes versucht :

> 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)

Ich erhalte jedoch denselben Fehler.

Was ist der Grund ? und wie kann ich das beheben?

Versuche es "0x28"stattdessen...
@goodvibration Danke. Ich habe es versucht, aber ich erhalte den gleichen Fehler! Ich habe es in meiner Frage erklärt. Es scheint merkwürdig !

Antworten (1)

Ich habe diese Funktion wie folgt aufgerufen und es funktioniert:

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)
});