Cannot do HTTP JSON RPC request on wallet #25635

issue apparently-davido opened this issue on July 18, 2022
  1. apparently-davido commented at 8:16 PM on July 18, 2022: none

    I'm trying to figure out how to query specific wallets.

    snippet of my config datadir=/data wallet=/data/wallets/test1/ wallet=/data/wallets/test2/

    view of the wallets
    user@container:/data# ls /data/wallets/test1/
    database  db.log  wallet.dat
    user@container:/data# ls /data/wallets/test2/
    database  db.log  wallet.dat
    
    user@container:/data# bitcoin-cli -conf=bitcoin.conf listwallets
    [
      "/data/wallets/test1/",
      "/data/wallets/test2/"
    ]
    
    no errors or issues via cli. the wallets are empty as expected as they were just created for testing
    user@container:/data# bitcoin-cli  -conf=bitcoin.conf  -rpcwallet=/data/wallets/test1/ listunspent
    [
    ]
    

    when I try an rpc curl request on it, I get the following error message curl -X POST --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listunspent", "params": [6, 9999999, [] , true, { "minimumAmount": 0.005 } ] }' -H 'Content-Type: application/json' 'https:/mynodeaddress.com/wallet/data/wallets/test2

    {"result":null,"error":{"code":-18,"message":"Requested wallet does not exist or is not loaded"},"id":"curltest"}

    Note this works if I place the wallet in /data/test1. the curl request will be successful if my config was wallet=test1 user@container:/data# ls /data/test1/ database db.log wallet.dat

    curl -X POST --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listunspent", "params": [6, 9999999, [] , true, { "minimumAmount": 0.005 } ] }' -H 'Content-Type: application/json' 'https:/mynodeaddress.com/wallet/test2

    it will return success fully return albeit an empty response similar to bitcoin-cli

    My question is, is it possible to have the wallet file in any directory within my datadir and still be able run rpc query against it using curl.

  2. apparently-davido added the label Bug on Jul 18, 2022
  3. bitcoin deleted a comment on Jul 18, 2022
  4. bitcoin deleted a comment on Jul 18, 2022
  5. liorwavebl commented at 3:25 PM on August 3, 2022: none

    I have the same issue with bitcoin CLI. I'm using v23.0 tag for testing.

  6. pinheadmz commented at 3:45 PM on March 8, 2023: member

    Your issue is that since your wallet name contains slashes, the http server is mis-reading the endpoint you are sending the request to. Or rather, it is reading it correctly but to sneak in those slashes you need to URI-encode you full wallet path.

    For example I created a wallet at the path /tmp/a/b/c/bitcoin/d/e/f.

    bitcoin-cli can handle the slashy wallet name:

    $ src/bitcoin-cli -regtest -datadir=/tmp/a/b/c/bitcoin -rpcuser=u -rpcpassword=p -rpcwallet=/tmp/a/b/c/bitcoin/d/e/f getbalances
    
    {
      "mine": {
        "trusted": 0.00000000,
        "untrusted_pending": 0.00000000,
        "immature": 0.00000000
      }
    }
    

    That's because internally it URI-encodes the wallet name.

    Here's an example of what you are currently doing that wont work, followed by a corrected example that does work:

    
    $ curl http://u:p@localhost:18443/wallet/tmp/a/b/c/bitcoin/d/e/f --data '{"method":"getbalances"}' | jq
    {
      "result": null,
      "error": {
        "code": -18,
        "message": "Requested wallet does not exist or is not loaded"
      },
      "id": null
    }
    
    $ curl http://u:p@localhost:18443/wallet/%2Ftmp%2Fa%2Fb%2Fc%2Fbitcoin%2Fd%2Fe%2Ff --data '{"method":"getbalances"}' | jq
    {
      "result": {
        "mine": {
          "trusted": 0,
          "untrusted_pending": 0,
          "immature": 0
        }
      },
      "error": null,
      "id": null
    }
    
  7. adamjonas commented at 8:23 PM on March 9, 2023: member

    Closing based on the above solution by @pinheadmz. Please ping if this doesn't resolve it.

  8. adamjonas closed this on Mar 9, 2023

  9. maflcko removed the label Bug on Mar 10, 2023
  10. maflcko added the label RPC/REST/ZMQ on Mar 10, 2023
  11. maflcko added the label Questions and Help on Mar 10, 2023
  12. bitcoin locked this on Mar 9, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me