0

Here's my code .

var Web3 = require("C:\\Users\\Administrator\\node_modules\\web3")
con_abi = [
    {
        "inputs": [],
        "name": "sloc111",
        "outputs": [
            {
                "internalType": "string",
                "name": "",
                "type": "string"
            }
        ],
        "stateMutability": "pure",
        "type": "function"
    }
]
con_addr = "0x0ed72dfd4c63dd97df8fec07e5a6bba466c6adf5";
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
var echoContract = new web3.eth.Contract(con_abi,con_addr);
// console.log(echoContract.sloc111);
// console.log(typeof(echoContract));
echoContract.methods.sloc111().call().then(console.log);

Error :

Error: hex data is odd-length (argument="value", value="0x0", code=INVALID_ARGUMENT, version=bytes/5.1.0)
    at Logger.makeError (C:\Users\Administrator\node_modules\@ethersproject\logger\lib\index.js:180:21)
    at Logger.throwError (C:\Users\Administrator\node_modules\@ethersproject\logger\lib\index.js:189:20)
    at Logger.throwArgumentError (C:\Users\Administrator\node_modules\@ethersproject\logger\lib\index.js:192:21)
    at Object.arrayify (C:\Users\Administrator\node_modules\@ethersproject\bytes\lib\index.js:79:24)
    at AbiCoder.decode (C:\Users\Administrator\node_modules\@ethersproject\abi\lib\abi-coder.js:93:53)
    at ABICoder.decodeParametersWith (C:\Users\Administrator\node_modules\web3-eth-abi\lib\index.js:304:30)
    at ABICoder.decodeParameters (C:\Users\Administrator\node_modules\web3-eth-abi\lib\index.js:285:17)
    at Contract._decodeMethodReturn (C:\Users\Administrator\node_modules\web3-eth-contract\lib\index.js:470:22)
    at Method.outputFormatter (C:\Users\Administrator\node_modules\web3-eth-contract\lib\index.js:760:42)
    at Method.formatOutput (C:\Users\Administrator\node_modules\web3-core-method\lib\index.js:147:54)
    at sendTxCallback (C:\Users\Administrator\node_modules\web3-core-method\lib\index.js:523:33)
    at C:\Users\Administrator\node_modules\web3-core-requestmanager\lib\index.js:308:9
    at XMLHttpRequest.request.onreadystatechange (C:\Users\Administrator\node_modules\web3-providers-http\lib\index.js:9
8:13)
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\Administrator\node_modules\xhr2-cookies\dist\xml-http-request-e
vent-target.js:34:22)
    at XMLHttpRequest._setReadyState (C:\Users\Administrator\node_modules\xhr2-cookies\dist\xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\Administrator\node_modules\xhr2-cookies\dist\xml-http-request.js:318:
14) {
  reason: 'hex data is odd-length',
  code: 'INVALID_ARGUMENT',
  argument: 'value',
  value: '0x0'
}

My TESTRPC version is

EthereumJS TestRPC v6.0.3 (ganache-core: 2.0.2)

Thank you!

2
  • The error is related to your ABI being incorrectly formatted, did you generate it using a tool or do it manually? May 3 at 9:24
  • I used Remix IDE to compile it.
    – Lee Tiger
    May 6 at 12:38
0

just change to value="0x00" so it is an even length byte

1
  • The '0x0' answer is returned by ganache to web3 so it is not easy to change before the exception is thrown.
    – Ismael
    Jul 16 at 7:18

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.