Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

eth_getBlockTransactionCountByNumber: cannot unmarshal non-string into Go value of type hexutil.Uint #364

Closed
cypherhat opened this issue Feb 25, 2018 · 5 comments

Comments

@cypherhat
Copy link

cypherhat commented Feb 25, 2018

I am trying to use Ganache as a testnet. I am using a Golang client with the latest release of Geth (1.8.1). I am trying to retrieve the eth_getBlockTransactionCountByNumber for an account that Ganache did not generate. Instead of returning 0 (zero) - which is what Geth returns when I use that for a testnet - Ganache errors out in:

func (ec *Client) PendingTransactionCount(ctx context.Context) (uint, error) {
	var num hexutil.Uint
	err := ec.c.CallContext(ctx, &num, "eth_getBlockTransactionCountByNumber", "pending")
	return uint(num), err
}

With: * json: cannot unmarshal non-string into Go value of type hexutil.Uint

Expected Behavior

I expect Ganache to return 0.

Current Behavior

Ganache fails.

Possible Solution

Steps to Reproduce (for bugs)

  1. Change the Chain ID and port for Ganache to 1977 and 8545 respectively.
  2. Create an account in my wallet:
$ vault write ethereum/accounts/ganache1 chain_id=1977
Key          Value
---          -----
address      0x1Cf3Ab9e24f1410869D8Ee3C16F536B1c6410073
blacklist    <nil>
chain_id     1977
rpc_url      http://localhost:8545
whitelist    <nil>
  1. Try to read the balance for that account:
 $ vault read ethereum/accounts/ganache1/balance
Error reading ethereum/accounts/ganache1/balance: Error making API request.

URL: GET https://localhost:8200/v1/ethereum/accounts/ganache1/balance
Code: 500. Errors:

* 1 error occurred:

* json: cannot unmarshal non-string into Go value of type hexutil.Uint
  1. Using geth (in a docker container) yields:
 $ vault read ethereum/accounts/ganache1/balance
Key                 Value
---                 -----
address             0x193947DD4fF0222C62A152Ff51c3c5D350eB7d87
pending_balance     0
pending_nonce       0
pending_tx_count    0

Context

I am building an Ethereum Wallet based on HashiCorp Vault: link here

Your Environment

@benjamincburns
Copy link
Contributor

benjamincburns commented Feb 27, 2018

Hi @cypherhat - thanks for reporting this. By any chance can you get hold of the problematic request to and response from Ganache and post them here?

Without seeing that, I can't say for certain what's wrong, but my best guess would be that we're either returning a response with neither a result nor an error field, or we're serializing either null or 0 when we should be serializing 0x0.

If it's the first issue, the the latest beta release may help. I've done a fair amount of work there on better error reporting.

Also if you're having trouble getting the request/response, try running ganache-cli with the --verbose flag. If you haven't used ganache-cli before, you'll need to install it with npm install -g ganache-cli.

@benjamincburns
Copy link
Contributor

benjamincburns commented Feb 27, 2018

Also you keep saying chain ID, but Ganache doesn't have a mechanism for allowing you to set chain ID. Perhaps you mean network ID (fetched via net_version)? If you do in fact mean chain ID, then you're likely making a false assumption about what's being set when you change the network ID. If you're not sure what I'm on about, I suggest seeing EIP-155 for more info.

@cypherhat
Copy link
Author

Getting the raw request/response is a little tricky at the moment - the error happens inside the go-ethereum codebase.

The distinction between network ID and chain ID is pretty poorly documented. Most places where both are discussed, within the context of private networks, they are treated as having the same value -
for example and this

But, you're right - I was conflating the two. I restored Ganache to its default network ID (1337) and assume that the underlying chain ID is the same. If not, perhaps you can explain.

My expectation was that when I make an RPC call to Ganache using the go-ethereum API, that I wouldn't get a marshaling error. I will try the new build soon.

Is the expectation that Ganache works just like a Geth node from a client's perspective?

@mikeseese
Copy link
Contributor

For posterity's sake: @davidmurdoch believes this may be related to trufflesuite/ganache#59

@davidmurdoch
Copy link
Member

@cypherhat, I wasn't able to reproduce the issue you describe here so I'm going to go ahead and close this one. If you are still experiencing problems with Ganache's eth_getBlockTransactionCountByNumber returning an invalid response please feel free to reopen with reproduction steps along with logs from Ganache's output.

Thanks again for reporting this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants