2

I have a running geth node and by using geth account new command I created a new account:

$ geth account list

Account #0: {47978a69f410d0f...} ...

Nevertheless, when using json rpc call to list my ether accounts a null result is obtained:

$ curl -X POST --data

'{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}' http://127.0.0.1:8545

{"jsonrpc":"2.0","id":1,"result":[]}

Why is that? Any hint? Thanks in advance!

I launched geth with the following command:

$geth --rpc --rpcapi "db,eth,net,web3" --rpcport "8545" --testnet 
--etherbase "0x47978a6...."

Is it possible that geth working on testnet gets confused on json rpc calls? Do I need to specify somehow in these calls to use testnet and not mainnet?

4
  • Try id:0 or remove id param.
    – niksmac
    Aug 19, 2016 at 10:48
  • Same result and error...: $ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":0}' http://127.0.0.1:8545 {"jsonrpc":"2.0","id":0,"result":[]} $ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[]}' http://127.0.0.1:8545 {"jsonrpc":"2.0","error":{"code":-32700,"message":"missing request id"}}´ Aug 19, 2016 at 15:11
  • What is id by the way? The id of what? Aug 19, 2016 at 15:13
  • 1
    eth.accounts[] is the index of the wallets that you are querying, in your case 0, the coinbase.
    – niksmac
    Aug 21, 2016 at 1:31

3 Answers 3

2

You don't need to use the params field in your call. By doing this, you are executing this command: eth.accounts[] which returns a null value. If you want to get a list of all the accounts, you should be executing eth.accounts. So, your RPC command should be:

curl -X POST -d '{"method":"eth_accounts","id":1}' 127.0.0.1:8545

P.S: I'm assuming you already enabled RPC on port 8545. Through the console, you can use admin.startRPC() to start RPC.

4
  • Thanks for the simplification, but unfortunatelly, same result: {"jsonrpc":"2.0","id":1,"result":[]} Aug 20, 2016 at 9:13
  • 1
    Did you check with other commands?
    – galahad
    Aug 20, 2016 at 13:36
  • Yes, it responds correctly to other commands: $ curl -X POST --data '{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}' localhost:8545 {"jsonrpc":"2.0","id":64,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"} Aug 20, 2016 at 18:00
  • Maybe problem is related to geth using testnet and json rpc using mainnet... is that possible? Aug 20, 2016 at 18:01
1

Enable the web3 RPC API when starting geth:

geth --rpc --rpcapi "web3" --rpcport "8545"

or if you want all APIs run:

geth --rpc --rpcapi "db,eth,net,web3" --rpcport "8545"
3
  • I just did it, but exactly the same result, geth account list shows the account but jsonrpc doesn't :-( Aug 19, 2016 at 15:36
  • Problem is not API not responding, but responding null result. In fact, it responds correctly to other commands such as: $ curl -X POST --data '{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}' localhost:8545 {"jsonrpc":"2.0","id":64,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"} Aug 20, 2016 at 17:59
  • It's likely that you are not sending the correct JSON object. Use web3 and call the same function: github.com/ethereum/wiki/wiki/JavaScript-API#web3ethaccounts as the curl parameters are correct (as suggested in the documentation).
    – Sebi
    Aug 20, 2016 at 18:39
1

Definitely the problem is related to node running on testnet and account being valid only on mainnet.

I created a new account on testnet and json-rpc query worked perfectly:

$geth --testnet account list

$geth --testnet account new Address: {3b877e80b5c0...}

$geth --testnet account list Account #0: {3b877e80b5c0...

$ curl -X POST -d '{"method":"eth_accounts","id":0}' 127.0.0.1:8545 {"jsonrpc":"2.0","id":0,"result":["0x3b877e80...

Thanks for your help!

1
  • In the original post the creation of the account does not have a --testnet command line option, so maybe that's the case. Did the OP trying to find the account on the mainnet? Oct 29, 2016 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.