Go-ethereum: Invalid hex number error for valid address

Created on 23 Jun 2017  路  12Comments  路  Source: ethereum/go-ethereum

System information

Geth version: 1.6.5-stable
OS & Version: OSX

Expected behaviour

Transaction is sent when receiver address is "0x088e62f69884781eb458e64b8d4e24c08a6ed9b5"

Actual behaviour

Transaction fails with:
Error: invalid argument 0: hex number has leading zero digits after 0x

Steps to reproduce the behaviour

...
var receiver = "0x088e62f69884781eb458e64b8d4e24c08a6ed9b5"
eth.sendTransaction({from:sender, to:receiver, value:amount, gas:limit, gasPrice:price});

Backtrace

Error: invalid argument 0: hex number has leading zero digits after 0x at web3.js:3104:20 at web3.js:6191:15 at web3.js:5004:36 at <anonymous>:1:1

Most helpful comment

Yeh must be the amount not being an int. But in any case the error was misleading.

All 12 comments

@fjl ping

The issue is related to "gas", "gasPrice" or "value" field. Leading zero is allowed for addresses.

These were my values copied direct from the console.

> sender
"0x914ef49db7caf5e4683e671cb6caf96db73bb93b"
> receiver
"0x088e62f69884781eb458e64b8d4e24c08a6ed9b5"
> amount
"0.859867396"
> limit
"21000"
> price
"25000000000"
> eth.sendTransaction({from:sender, to:receiver, value:amount, gas:limit, gasPrice:price});
Error: invalid argument 0: hex number has leading zero digits after 0x
    at web3.js:3104:20
    at web3.js:6191:15
    at web3.js:5004:36
    at <anonymous>:1:1

I tried sending again today to the 0x0... address with a restarted console and different values and it worked. Strange.

I'm unsure about the amount being a fractional number. I though it must be an int in Wei. Perhaps that could have been the issue?

Yeh must be the amount not being an int. But in any case the error was misleading.

FYI, here is error message from master

eth.sendTransaction({from: eth.coinbase, to: "0x0166be393b7ded951d9c171d1241312a588014d2", value: "0.85"});
Error: invalid argument 0: json: cannot unmarshal hex number with leading zero digits into Go struct field SendTxArgs.value of type *hexutil.Big
    at web3.js:3104:20
    at web3.js:6191:15
    at web3.js:5004:36
    at <anonymous>:1:11

Closing because the error message is improved now.

Just leaving a note here cause I ran into this on an old machine: value should be an integer (in Wei) and not a fraction of an Ether.

invalid argument 0: json: cannot unmarshal hex number with leading zero digits into Go struct field CallArgs.value of type *hexutil.Big

what is this

cannot unmarshal hex number with leading zero digits into Go struct field CallArgs.gas of type hexutil.Uint64
what is this

Don't pass number arguments with leading zero digits.

My solution is to replace leading zero directly at the library. Looks like that:

Eth.prototype.sendAsync = function sendAsync(opts, cb) {
  if (opts.method == "eth_estimateGas"){
    if (opts.params[0].value.toString()[2] === '0')
        opts.params[0].value = opts.params[0].value.toString().replace('0x0', '0x');
  }
  var self = this;
  self.idCounter = self.idCounter % self.options.max;
  self.currentProvider.sendAsync(createPayload(opts, self.idCounter++), function (err, response) {
    var responseObject = response || {};
    if (err || responseObject.error) return cb(new Error('[ethjs-query] ' + (responseObject.error && 'rpc' || '') + ' error with payload ' + JSON.stringify(opts, null, 0) + ' ' + JSON.stringify(err || response.error, null, 0)));
    return cb(null, response.result);
  });
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

vogelito picture vogelito  路  3Comments

bgrieder picture bgrieder  路  3Comments

VoR0220 picture VoR0220  路  3Comments

freshonline picture freshonline  路  3Comments

AdrianScott picture AdrianScott  路  3Comments