ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
477 stars 186 forks source link

"Unhandled rejection RpcError: Wallet file not specified" when attempting to get wallet balance #86

Closed jbeard4 closed 5 years ago

jbeard4 commented 5 years ago

Hi,

I am attempting to execute the following script:

const Client = require('bitcoin-core');
const client = new Client({
  username: 'myuser',
  password: 'mypassword',
  //wallet: 'wallet.dat',  //also tried this
  wallet: 'MyWallet',
  version: '0.17.0'
});

client.getBalance().then((help) => console.log(help));

Expected behavior is to get the balance of MyWallet. Actual behavior is the following error:

Unhandled rejection RpcError: Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path).
    at getRpcResult (/home/jacob/bitcoin-daemon/node_modules/bitcoin-core/dist/src/parser.js:39:11)
    at Client.rpc (/home/jacob/bitcoin-daemon/node_modules/bitcoin-core/dist/src/parser.js:82:14)
    at Client.tryCatcher (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/promise.js:694:18)
    at Promise._fulfill (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/promise.js:638:18)
    at Request._callback (/home/jacob/bitcoin-daemon/node_modules/bluebird/js/release/nodeback.js:45:21)
    at Request.self.callback (/home/jacob/bitcoin-daemon/node_modules/request/request.js:185:22)
    at emitTwo (events.js:131:20)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/jacob/bitcoin-daemon/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/jacob/bitcoin-daemon/node_modules/request/request.js:1083:12)

This is with bitcoin-core@2.0.0 and bitcoind 0.17.0.

Here is the output from bitcoin-cli and bitcoind, which shows the wallet works well with bitcoin-cli:

jacob@nas:~$ bitcoin-cli --rpcuser=myuser --rpcpassword=mypassword listwallets
[
  ""
]
jacob@nas:~$ bitcoin-cli --rpcuser=myuser --rpcpassword=mypassword loadwallet MyWallet
{
  "name": "MyWallet",
  "warning": ""
}
jacob@nas:~$ bitcoin-cli --rpcuser=myuser --rpcpassword=mypassword --rpcwallet=MyWallet listtransactions ossmo
[
  {
    "address": "3KDCq1xykKRkY5bjDQrruXayB8jfGELJ2K",
    "category": "receive",
    "amount": 0.00100000,
    "label": "ossmo",
    "vout": 1,
    "confirmations": 291,
    "blockhash": "000000000000000000058986412b2e8f391720d58e7159ba18693e632f5b7c4a",
    "blockindex": 653,
    "blocktime": 1548029827,
    "txid": "f127e1f45647e0b7596ecdaa68f7ec3d908f2daa8aa4bb3c6321963070bff3dc",
    "walletconflicts": [
    ],
    "time": 1548029827,
    "timereceived": 1548207980,
    "bip125-replaceable": "no"
  }
]

bitcoind:

2019-01-23T01:46:19Z Using wallet wallet.dat
2019-01-23T01:46:19Z BerkeleyEnvironment::Open: LogDir=/vol0/bitcoin/MyWallet/database ErrorFile=/vol0/bitcoin/MyWallet/db.log
2019-01-23T01:46:19Z init message: Loading wallet...
2019-01-23T01:46:19Z [MyWallet] nFileVersion = 170100
2019-01-23T01:46:19Z [MyWallet] Keys: 0 plaintext, 4002 encrypted, 4002 w/ metadata, 4002 total. Unknown wallet records: 1
2019-01-23T01:46:19Z [MyWallet] Wallet completed loading in             152ms
2019-01-23T01:46:19Z init message: Rescanning...
2019-01-23T01:46:19Z [MyWallet] Rescanning last 51569 blocks (from block 508112)...
2019-01-23T01:46:19Z [MyWallet] Rescan started from block 559378...
2019-01-23T01:46:20Z [MyWallet] AddToWallet f127e1f45647e0b7596ecdaa68f7ec3d908f2daa8aa4bb3c6321963070bff3dc  new
2019-01-23T01:46:35Z [MyWallet] Rescan completed in           15274ms
2019-01-23T01:46:35Z [MyWallet] setKeyPool.size() = 1999
2019-01-23T01:46:35Z [MyWallet] mapWallet.size() = 1
2019-01-23T01:46:35Z [MyWallet] mapAddressBook.size() = 1

My wallet file is /vol0/bitcoin/wallet.dat

I would appreciate any insight you could share on this. Thank you.

pedrobranco commented 5 years ago

The multi-wallet feature is only available on the next release (soon). You can add this package as a direct github dependency (branch master) and have early access to this multi-wallet feature.