我正在尝试使用 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