Zcash wallet RPC API

I have a Windows app I created that lets me manage all of my cryptocoin wallets from a single GUI. It uses the wallet the RPC API. However, I cannot get it to work with zcash. I have the zcash wallet running on an Ubuntu system and my app runs on a Windows laptop. I admit, I am a novice with Ubuntu but the zcash wallet is up and running and it has synched successfully. I can issue commands through the zcash-cli method locally and it works.

However, when I attempt to POST an http request to the zcash wallet from my windows app over a local area network I get an error “(401) Unauthorized” - this error typically indicates the userID or password is incorrect. I have verified and re-verified that the rpcuser and rpcpassword in the zcash.conf file are correct. As I said, I am using the same app to connect to several other wallets (all running on windows systems).

The zcash.conf file includes rpcallowip and rpcport (if these were wrong this would throw a different error - which I have tested).

Is there any reason the http post to the zcash RPC function would not work?

Thanks in advance for any help you can provide.

If you’re attempting to use a REST call, that has been disabled in the Zcash client.

https://github.com/zcash/zcash/blob/master/doc/security-warnings.md#rest-interface

The only reasons for 401 to RPC from zcashd seem to be abcence of “Authorization” header or wrong credentials.

You may try to test your access with something like this (with correct address, port and user):

wget -O- --auth-no-challenge --http-user=rpcuser --ask-password --post-data='{"method":"getinfo","params":[],"id":1}' 'http://127.0.0.1:8232'

Is it possible that there is a firewall interfering with the communication between the Windows app and zcashd?

What version of zcashd are you using?

I was able to get wget to work from the local machine (the only Ubuntu instance I am running. I supplied --http-password instead of --ask-password.

In any case, I thought I disabled ufw but I will check to be sure. Is that the only firewall that comes with Ubuntu?

Thanks again.

I downloaded and installed wget for windows did this:

wget -O- --auth-no-challenge --http-user=testRPC --http-password=secret --post-data=‘{“method”:“getinfo”,“params”:[],“id”:1}’ http://n.n.n.n:8232

Result:

_–2017-04-17 14:37:30-- http://n.n.n.n:8232/_
Connecting to n.n.n.n:8232… connected.
HTTP request sent, awaiting response… 500 Internal Server Error
2017-04-17 14:37:30 ERROR 500: Internal Server Error.

Firewall (ufw) is disabled.

Thanks again for any help.

if you do this in windows console (command line), single quotes have different meaning there.

you may try --post-file option instead of --post-data with file containing correct content

1 Like

Don’t know if this is significant but after running the full-test-suite, I found this in the test log.

test/rpc_wallet_tests.cpp(283): error: in “rpc_wallet_tests/rpc_wallet”: unexpected exception thrown by CallRPC(“getblock 0”)

*** 1 failure is detected in the test module “Bitcoin Test Suite”

rpc-tests turned up no errors.

First, I want to thank those who responded to my question for their help. Your suggestions helped me zero in on the exact problem I was having.

…which I finally solved!. For future reference in case anyone else has this problem, the issue turned out to be the way windows provides the credentials to the http request handler in the wallet. Using the request Credentials property to provide the USER and password results in an authentication error (401 - Unauthorized). The solution is to build and add the authorization header in code instead.

I have not yet determined why this solution works or why the Credentials property doesn’t. Since both methods work for my Windows based wallets I am assuming there is some kind of encoding difference going from Windows to Ubuntu that is resolved by creating the header manually.

2 Likes