3

I have a view-only wallet opened, and from another terminal, I try to run the getbalance example from the Wallet RPC documentation. However, I get a Connection refused error:

mac:~ user$ curl -X POST http://127.0.0.1:18082/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"getbalance"}' -H 'Content-Type: application/json'
curl: (7) Failed connect to 127.0.0.1:18082; Connection refused

This is on macOS (Mavericks). Anyone knows why? Should I start the wallet with extra parameters?

dpzz
  • 4,539
  • 4
  • 22
  • 46

2 Answers2

2

If I recall, RPC is disabled by default, and needs to be explicitly enabled when running the wallet.

I tried it out and got it working by using the command:

monero-wallet-cli --restricted-rpc --rpc-bind-port 18082 --wallet-file <wallet path here> --password <wallet password here>

The program will then listen and wait for rpc commands sent to it on 127.0.0.1 . The command in your post should then work.

ferretinjapan
  • 6,494
  • 2
  • 20
  • 47
0

I believe for wallet RPC calls you need to set the --user-agent field now. So, when you launch the wallet in RPC mode (you need to set --rpc-bind-port 18082, as user36303 mentioned), you need to set the --user-agent to be some string of your choice. This is in response to the vulnerability disclosed here:
https://labs.mwrinfosecurity.com/advisories/csrf-vulnerability-allows-for-remote-compromise-of-monero-wallets/

Then, when you make the RPC call you need to set the User-Agent field of the http header to whatever you set it on the command line when launching monero-wallet-cli.

It looks like from the error message that maybe you're not binding an rpc-port though, and the connection is just being refused because monero-wallet-cli isn't listening on that (or any) port.

jwinterm
  • 4,413
  • 1
  • 21
  • 34