我正在尝试使用bitcoinj获取钱包余额,这是我正在尝试的代码,但它总是返回0
BriefLogFormatter.init();
NetworkParameters params ;
String net = "testnet"; //choosing network
if (net.equals("testnet")) {params = TestNet3Params.get();
} else if (net.equals("regtest")) {params = RegTestParams.get();
} else {params = MainNetParams.get();}
String privKey = "key-here";
BigInteger test = new BigInteger(privKey);
ECKey key = ECKey.fromPrivate(test);//initializing key
Wallet wallet = new Wallet(params);
wallet.importKey(key); //puting key in wallet
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain = new BlockChain(params, wallet, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addWallet(wallet);
peerGroup.startAsync(); //syncing with the blockchain
System.out.println( wallet.getBalance().toString());//getting balance
暂无答案!
目前还没有任何答案,快来回答吧!