Is there anyone using Monero JSON RPC authentication? I can only use curl with username:password to request the daemon RPC. But I cannot do the request with nodejs. Anyone tried with nodejs successfully with digest auth?
3 Answers
I've got a working JSON RPC wrapper with digest auth working in https://github.com/sneurlax/moneronodejs (merging into https://github.com/monero-integrations/moneronodejs, I hope.) Here's the relevant code:
lib/walletRPC.js
var request = require('request-promise');
...
_run(method, params) {
let options = {
forever: true,
json: {'jsonrpc': '2.0', 'id': '0', 'method': method}
auth: {
'user': 'rpcuser',
'pass': 'rpcpass',
'sendImmediately': false
},
params: params
};
return request.post(`http://127.0.0.1:28083/json_rpc`, options)
.then((result) => {
return result;
});
}
EDIT: also, in my library I have to call a throwaway get_balance()
... the first call always fails for me, but subsequent calls work fine.

- 21
- 4
Try urllib it will work with simple and disgest auth.
const httpClient = require('urllib');
const url = 'https://site.domain.com/xmlapi/xmlapi';
const options = {
method: 'POST',
rejectUnauthorized: false,
// auth: "username:password" use it if you want simple auth
digestAuth: "username:password",
content: "Hello world. Data can be json or xml.",
headers: {
//'Content-Type': 'application/xml' use it if payload is xml
//'Content-Type': 'application/json' use it if payload is json
'Content-Type': 'application/text'
}
};
const responseHandler = (err, data, res) => {
if (err) {
console.log(err);
}
console.log(res.statusCode);
console.log(res.headers);
console.log(data.toString('utf8'));
}
httpC
lient.request(url, options, responseHandler);

- 101
- 1
I haven't used digest auth with nodejs but I have used it with PHP to communicate with the rpc wallet. Here's what I did:
First, start monero-wallet-rpc
with --rpc-login username:password
.
Then, in your code to connect to the wallet, use:
IP=127.0.0.1
PORT=18082
METHOD="make_integrated_address"
PARAMS="{\"payment_id\":\"1234567890123456789012345678900012345678901234567890123456789000\"}"
curl \
-u username:password --digest \
-X POST http://$IP:$PORT/json_rpc \
-d '{"jsonrpc":"2.0","id":"0","method":"'$METHOD'","params":'"$PARAMS"'}' \
-H 'Content-Type: application/json'
Substitute your username and password as needed, as well as the other fields such as the METHOD.

- 406
- 2
- 7
-
That's curl, not PHP though ? The asker says they tried with curl already. – user36303 Jan 27 '18 at 19:44