0

So I want to load a wallet and get its balance also sending some funds with the corresponding wallet, here is my code

public class DumpWallet {
public static void main(String[] args) throws Exception {


    Wallet wallet = Wallet.loadFromFile(new File("wallet.dat"));
    System.out.println(wallet.toString());
}
}

Why does it throw these followings error (I am using wallet.dat that created automatically on C:\Users\<username>\AppData\Roaming\Bitcoin\testnet3

Exception in thread "main" org.bitcoinj.wallet.UnreadableWalletException: Could not parse input stream to protobuf
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:427)
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:399)
at org.bitcoinj.wallet.Wallet.loadFromFileStream(Wallet.java:1581)
at org.bitcoinj.wallet.Wallet.loadFromFile(Wallet.java:1487)
at org.bitcoinj.examples.DumpWallet.main(DumpWallet.java:33)
Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
    at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
    at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:158)
    at org.bitcoinj.wallet.Protos$Wallet.<init>(Protos.java:14789)
    at org.bitcoinj.wallet.Protos$Wallet.<init>(Protos.java:14778)
    at org.bitcoinj.wallet.Protos$Wallet$1.parsePartialFrom(Protos.java:14956)
    at org.bitcoinj.wallet.Protos$Wallet$1.parsePartialFrom(Protos.java:1)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:89)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:95)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
    at org.bitcoinj.wallet.Protos$Wallet.parseFrom(Protos.java:15822)
    at org.bitcoinj.wallet.WalletProtobufSerializer.parseToProto(WalletProtobufSerializer.java:606)
    at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:420)
    ... 4 more
1

Bitcoinj doesn't read Bitcoin Core wallet.dat files. You need to start a fresh wallet and move coins into it using a standard Bitcoin transaction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.