How do i add some balance to my wallet?

48 views
Skip to first unread message

v e

unread,
Nov 10, 2017, 5:34:09 PM11/10/17
to bitcoinj
Hi,

This is my first time coding using this library and looking at the documentation i could able to create a wallet.
Now I am trying to send some coins in test3network, how do load my wallet with some coins programmatically?

thanks

Ajit Soman

unread,
Nov 13, 2017, 12:09:00 PM11/13/17
to bitcoinj
use testnet faucet to send test bitcoin to your wallet address. link: https://testnet.manu.backend.hamburg/faucet.

Use  below code to load wallet file and get balance:

File file = new File("195da336-a311-4f69-8707-fcfb5f61dd5a.dat");
 
Wallet wallet = Wallet.loadFromFile(file);
       
System.out.println(wallet.getBalance().toFriendlyString());
 
       
// Set up the components and link them together.
 
final NetworkParameters params = TestNet3Params.get();
 
BlockStore blockStore = new MemoryBlockStore(params);
 
BlockChain chain = new BlockChain(params, wallet, blockStore);


 
final PeerGroup peerGroup = new PeerGroup(params, chain);
 peerGroup
.setFastCatchupTimeSecs(wallet.getEarliestKeyCreationTime());
 peerGroup
.startAsync();
 
// Now download and process the block chain.
 peerGroup
.downloadBlockChain();
        peerGroup
.stopAsync();
        wallet
.saveToFile(file);
       
       
System.out.println("Synchronization completed");
       
System.out.println(wallet.getBalance().toFriendlyString());

v e

unread,
Nov 13, 2017, 1:10:19 PM11/13/17
to bitc...@googlegroups.com
Thanks ajit,

I am trying to create a new Wallet by giving something like:

Wallet wallet = new Wallet(params);
wallet.autosaveToFile(new File("app.wallet"), 1000, TimeUnit.MILLISECONDS,null);
peerGrp.addWallet(wallet);

If i create a new wallet how do i initialize the balance instead of using the existing ones?

--
You received this message because you are subscribed to a topic in the Google Groups "bitcoinj" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bitcoinj/tujoTbBy4j4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bitcoinj+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ajit Soman

unread,
Nov 13, 2017, 1:26:15 PM11/13/17
to bitcoinj
Try this one to create wallet :


public class WalletCreation {
public static void main(String[] args) throws IOException{
int bits = 128;
SecureRandom random = new SecureRandom();
DeterministicKeyChain determinstickeychain = new DeterministicKeyChain(random, bits);
DeterministicSeed seed = determinstickeychain.getSeed();
System.out.println("seed " + seed.getSeedBytes());
Wallet wallet = Wallet.fromSeed(TestNet3Params.get(), seed);
ECKey eckey = new ECKey();
wallet.importKey(eckey);
wallet.saveToFile(new File(UUID.randomUUID().toString()+".dat"));
System.out.println("Wallet has been created");
System.out.println("wallet address--->"+wallet.currentReceiveAddress());
System.out.println("wallet balance -->"+wallet.getBalance().toFriendlyString());
To unsubscribe from this group and all its topics, send an email to bitcoinj+u...@googlegroups.com.

Ajit Soman

unread,
Nov 13, 2017, 1:26:49 PM11/13/17
to bitcoinj
My previous code create a HD wallet
Reply all
Reply to author
Forward
0 new messages