1、異常信息 Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)
Exception in thread "main" wf.bitcoin.javabitcoindrpcclient.BitcoinRPCException: RPC Query Failed (method: getbalance, params: [], response code: 500 responseMessage Internal Server Error, response: {"result":null,"error":{"code":-19,"message":"Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)."},"id":"1"} at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.query(BitcoinJSONRPCClient.java:236) at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.getBalance(BitcoinJSONRPCClient.java:294) at com.lpz.exchange.biz.TestBitcoinCore.javaBitcoin(TestBitcoinCore.java:46) at com.lpz.exchange.biz.TestBitcoinCore.main(TestBitcoinCore.java:74) Process finished with exit code 1
原因:由於bitcoin core 客戶端里面創建了多個錢包,java連接的時候未指明使用某個錢包而產生的
解決: URL url = new URL("http://user:password@127.0.0.1:18332"); 在連接后面加上錢包名稱
Eq: 我有個錢包名叫:lpz
那么連接就因該是: URL url = new URL("http://user:password@127.0.0.1:18332/wallet/lpz"); 在連接后面加上錢包名稱
錢包里面有個默認的錢包,連接是就不加名稱 URL url = new URL("http://user:password@127.0.0.1:18332/wallet/");
2、異常信息 Error: Please enter the wallet passphrase with walletpassphrase first.
Exception in thread "main" wf.bitcoin.javabitcoindrpcclient.BitcoinRPCException: RPC Query Failed (method: dumpprivkey, params: [2N1y1DGtXUbajM5SWyo9yRgiWAqQcPUyVEA], response code: 500 responseMessage Internal Server Error, response: {"result":null,"error":{"code":-13,"message":"Error: Please enter the wallet passphrase with walletpassphrase first."},"id":"1"} at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.query(BitcoinJSONRPCClient.java:236) at com.lpz.exchange.biz.TestBitcoinCore.javaBitcoin(TestBitcoinCore.java:56) at com.lpz.exchange.biz.TestBitcoinCore.main(TestBitcoinCore.java:74) Process finished with exit code 1
原因:調用dumppivkey (獲取私鑰) 的時候需要先輸入錢包密碼,沒有輸入密碼就調用此方法拋出的異常
解決:在調用獲取私鑰方法之前輸入錢包密碼:bitcoinClient.walletPassPhrase("你的錢包密碼",超時時間);
Eq:
bitcoinClient.walletPassPhrase("lpz",60); String addressPrivateKey=bitcoinClient.query("dumpprivkey","2N1y1DGtXUbajM5SWyo9yRgiWAqQcPUyVEA").toString(); logger.info("獲取地址私鑰:"+ addressPrivateKey);
還有其它的方法也是需要輸入密碼的,主要是看它提示什么,或者你在bitcoin core控制台線調用一下方法