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?

| improve this question | | | | |

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:


  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(``, 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.

| improve this answer | | | | |

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:

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.

| improve this answer | | | | |
  • That's curl, not PHP though ? The asker says they tried with curl already. – user36303 Jan 27 '18 at 19:44

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) {

lient.request(url, options, responseHandler);

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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