Skip to content

Cannot unmarshal hex number with leading zero digits into Go struct field #59

@sfurionix

Description

@sfurionix

Example response from Eth: Client RPC error response [uri] / [method] eth_estimateGas [error code] -32602 [error message] invalid argument 0: json: cannot unmarshal hex number with leading zero digits into Go struct field CallArgs.value of type *hexutil.Big
Method EthQ::hexValUnpadded() must return a string without leading zeros. For example, 0.2 ether (200000000000000000 wei) should be converted to 0x2c68af0bb140000 instead of 0x02c68af0bb140000.

Suggesting changes:

--- src/DataType/EthQ.php
+++ src/DataType/EthQ.php
@@ -282,7 +282,7 @@ class EthQ extends EthD
      */
     public function hexValUnpadded()
     {
-        return '0x' . $this->value->toHex($this->value->is_negative);
+        return '0x' . ltrim($this->value->toHex($this->value->is_negative), '0');
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions