{"action":"created","issue":{"url":"https://api.github.com/repos/trufflesuite/ganache-core/issues/166","repository_url":"https://api.github.com/repos/trufflesuite/ganache-core","labels_url":"https://api.github.com/repos/trufflesuite/ganache-core/issues/166/labels{/name}","comments_url":"https://api.github.com/repos/trufflesuite/ganache-core/issues/166/comments","events_url":"https://api.github.com/repos/trufflesuite/ganache-core/issues/166/events","html_url":"https://github.com/trufflesuite/ganache-core/issues/166","id":356857200,"node_id":"MDU6SXNzdWUzNTY4NTcyMDA=","number":166,"title":"Compatibility: cannot unmarshal hex number with leading zero digits into Go struct","user":{"login":"gislik","id":943039,"node_id":"MDQ6VXNlcjk0MzAzOQ==","avatar_url":"https://avatars1.githubusercontent.com/u/943039?v=4","gravatar_id":"","url":"https://api.github.com/users/gislik","html_url":"https://github.com/gislik","followers_url":"https://api.github.com/users/gislik/followers","following_url":"https://api.github.com/users/gislik/following{/other_user}","gists_url":"https://api.github.com/users/gislik/gists{/gist_id}","starred_url":"https://api.github.com/users/gislik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gislik/subscriptions","organizations_url":"https://api.github.com/users/gislik/orgs","repos_url":"https://api.github.com/users/gislik/repos","events_url":"https://api.github.com/users/gislik/events{/privacy}","received_events_url":"https://api.github.com/users/gislik/received_events","type":"User","site_admin":false},"labels":[{"id":1023295614,"node_id":"MDU6TGFiZWwxMDIzMjk1NjE0","url":"https://api.github.com/repos/trufflesuite/ganache-core/labels/correctness/consistency","name":"correctness/consistency","color":"9d70d8","default":false},{"id":1023256854,"node_id":"MDU6TGFiZWwxMDIzMjU2ODU0","url":"https://api.github.com/repos/trufflesuite/ganache-core/labels/needs%20validation","name":"needs validation","color":"29559e","default":false},{"id":1023295500,"node_id":"MDU6TGFiZWwxMDIzMjk1NTAw","url":"https://api.github.com/repos/trufflesuite/ganache-core/labels/priority-high","name":"priority-high","color":"ff0000","default":false}],"state":"closed","locked":false,"assignee":{"login":"eshaben","id":26533957,"node_id":"MDQ6VXNlcjI2NTMzOTU3","avatar_url":"https://avatars2.githubusercontent.com/u/26533957?v=4","gravatar_id":"","url":"https://api.github.com/users/eshaben","html_url":"https://github.com/eshaben","followers_url":"https://api.github.com/users/eshaben/followers","following_url":"https://api.github.com/users/eshaben/following{/other_user}","gists_url":"https://api.github.com/users/eshaben/gists{/gist_id}","starred_url":"https://api.github.com/users/eshaben/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eshaben/subscriptions","organizations_url":"https://api.github.com/users/eshaben/orgs","repos_url":"https://api.github.com/users/eshaben/repos","events_url":"https://api.github.com/users/eshaben/events{/privacy}","received_events_url":"https://api.github.com/users/eshaben/received_events","type":"User","site_admin":false},"assignees":[{"login":"eshaben","id":26533957,"node_id":"MDQ6VXNlcjI2NTMzOTU3","avatar_url":"https://avatars2.githubusercontent.com/u/26533957?v=4","gravatar_id":"","url":"https://api.github.com/users/eshaben","html_url":"https://github.com/eshaben","followers_url":"https://api.github.com/users/eshaben/followers","following_url":"https://api.github.com/users/eshaben/following{/other_user}","gists_url":"https://api.github.com/users/eshaben/gists{/gist_id}","starred_url":"https://api.github.com/users/eshaben/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eshaben/subscriptions","organizations_url":"https://api.github.com/users/eshaben/orgs","repos_url":"https://api.github.com/users/eshaben/repos","events_url":"https://api.github.com/users/eshaben/events{/privacy}","received_events_url":"https://api.github.com/users/eshaben/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-09-04T15:13:47Z","updated_at":"2018-12-05T01:16:24Z","closed_at":"2018-12-05T01:16:24Z","author_association":"NONE","body":"The [ethclient](https://github.com/ethereum/go-ethereum/blob/master/ethclient/ethclient.go) fails parsing a transaction received from ganache over RPC. \r\n\r\n## Expected Behavior\r\nIt should parse the JSON response.\r\n\r\n## Current Behavior\r\n    json: cannot unmarshal hex number with leading zero digits into Go struct field txdata.nonce of type hexutil.Uint64\r\n\r\n## Possible Solution\r\nethclient expects the following transaction fields to hex encodings of a number without any leading zeros:\r\n\r\n- `nonce`\r\n- `gasPrice`\r\n- `gasLimit`\r\n- `value`\r\n- `input`\r\n- `v`\r\n- `r`\r\n- `s` \r\n\r\nTherefore a `nonce` of 0x02 will fail to parse but 0x2 will succeed.\r\n\r\n## Steps to Reproduce (for bugs)\r\n1. Start a ganache on port 9545 (`ganache-cli -p 9545`).\r\n2. Connect using web3 (`npx truffle console`).\r\n3. `web3.eth.sendTransaction({from: web3.eth.accounts[0], to: web3.eth.accounts[1], value: 0})` (nonce 0 will be encoded correctly as `0x0`).\r\n4. `web3.eth.sendTransaction({from: web3.eth.accounts[0], to: web3.eth.accounts[1], value: 0})` (nonce 1 will be encoded incorrectly as `0x01`).\r\n5. Use the attached go program to lookup the tx hex returned from step 4.\r\n6. Program crashes.\r\n\r\n## Context\r\nAccording to the [JSON-RPC specification](https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding) hex quantity values should be encoded as follows:\r\n\r\n    When encoding QUANTITIES (integers, numbers): encode as hex, prefix with \"0x\", the most compact representation (slight exception: zero should be represented as \"0x0\"). Examples:\r\n\r\n    0x41 (65 in decimal)\r\n    0x400 (1024 in decimal)\r\n    WRONG: 0x (should always have at least one digit - zero is \"0x0\")\r\n    WRONG: 0x0400 (no leading zeroes allowed)\r\n    WRONG: ff (must be prefixed 0x)\r\n\r\nganache should adhere to the spec.\r\n\r\n~~~~golang\r\npackage main\r\n\r\nimport (\r\n  \"context\"\r\n  \"log\"\r\n  \"os\"\r\n\r\n  \"github.com/ethereum/go-ethereum/common\"\r\n  \"github.com/ethereum/go-ethereum/ethclient\"\r\n)\r\n\r\nfunc main() {\r\n  if len(os.Args) != 2 {\r\n    log.Fatal(\"Usage: ./transaction <tx-hex>\")\r\n  }\r\n  h := os.Args[1]\r\n  conn, err := ethclient.Dial(\"http://localhost:9545\")\r\n\r\n  if err != nil {\r\n    log.Fatalf(\"Failed to connect to the Ethereum client: %v\", err)\r\n  }\r\n\r\n  t, _, err := conn.TransactionByHash(context.Background(), common.HexToHash(h))\r\n  if err != nil {\r\n    log.Fatal(err)\r\n  }\r\n  log.Printf(\"%#v\\n\", t)\r\n}\r\n~~~~\r\n\r\n## Your Environment\r\n* Version used: All versions, including `develop` branch.\r\n* Operating System and version: Linux e 4.15.12-x86_64-linode105 SMP Thu Mar 22 02:13:40 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\r\n"},"comment":{"url":"https://api.github.com/repos/trufflesuite/ganache-core/issues/comments/444321137","html_url":"https://github.com/trufflesuite/ganache-core/issues/166#issuecomment-444321137","issue_url":"https://api.github.com/repos/trufflesuite/ganache-core/issues/166","id":444321137,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDMyMTEzNw==","user":{"login":"eshaben","id":26533957,"node_id":"MDQ6VXNlcjI2NTMzOTU3","avatar_url":"https://avatars2.githubusercontent.com/u/26533957?v=4","gravatar_id":"","url":"https://api.github.com/users/eshaben","html_url":"https://github.com/eshaben","followers_url":"https://api.github.com/users/eshaben/followers","following_url":"https://api.github.com/users/eshaben/following{/other_user}","gists_url":"https://api.github.com/users/eshaben/gists{/gist_id}","starred_url":"https://api.github.com/users/eshaben/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eshaben/subscriptions","organizations_url":"https://api.github.com/users/eshaben/orgs","repos_url":"https://api.github.com/users/eshaben/repos","events_url":"https://api.github.com/users/eshaben/events{/privacy}","received_events_url":"https://api.github.com/users/eshaben/received_events","type":"User","site_admin":false},"created_at":"2018-12-05T01:16:24Z","updated_at":"2018-12-05T01:16:24Z","author_association":"MEMBER","body":"Thanks @gislik for submitting this issue! We have fixed the incorrect encoding of the `nonce` field in the transaction object. I am going to go ahead and close this issue since I have verified that the nonce field is now being correctly encoded in `ganache-core` version 2.3.1!\r\n\r\n@elv-gilles, thank you for taking the time to comment here and for also submitting the issue with `go-ethereum`. It looks like there are definitely some inconsistencies. I can see your concerns, but since the JSON-RPC spec states that `r` and `s` are `DATA` fields and `v` is a `QUANTITY` field, we will make the recommended change to the `v` field as that should be a `QUANTITY` datatype and keep an eye on `go-ethereum` to respond to your issue and make the required changes to the `r` and `s` fields.  "}}
{"actor":{"display_login":"eshaben"}}