CryptoCoinsInfoClub.com

Bitcoinj Private Key

How Can I Hardcode A Private Key In Bitcoinj - Eckey Constructor?

How Can I Hardcode A Private Key In Bitcoinj - Eckey Constructor?

how can I hardcode a private key in bitcoinJ - ECKey constructor? Can someone please explain how to use the following constructor (listed here ): ECKey(BigInteger priv, org.spongycastle.math.ec.ECPoint pub) How do I get the big integer representation of it (in other words, and if I understood correctly, is there a function to go from check58 to biginteger?) , and If all you are after is getting an ECKey object for that private key, then Bitcoinj has a DumpedPrivateKey class for just such an occasion. import org.bitcoinj.core.ECKey;import org.bitcoinj.core.DumpedPrivateKey;import org.bitcoinj.params.MainNetParams;public class Example { public static void main(String[] args) { String priv = "L4...5"; ECKey key = DumpedPrivateKey.fromBase58(MainNetParams.get(), priv).getKey(); }} If you would like to use an ECKey constructor explicitly, then you should be able to get the code you need from here: With respect to the constructor you listed, it is a protected constructor, so it's probably not one you would be looking to use. It lists a private key and public key parameters. The private key may be null if the ECKey instance is only going to be used for verifying signatures, not actually producing them. The public key must not be null, and it saves time by not needing to re-compute the public key, which is a CPU intensive operation. Note that most of the public ECKey constructors are deprecated. The preferred way of creating the ECKey objects now is to use the static factory methods. Continue reading >>

Interactive Algorithms Textbook In Java: Bitcoin Tutorial Part1

Interactive Algorithms Textbook In Java: Bitcoin Tutorial Part1

Welcome to the Bitcoin Java Programming Tutorial Click the run button at the bottom of this section! This interactive tutorial uses BitcoinJ. You can modify the code examples in your browser. This coding system has internet disabled, so do not use it to send or receive real money! You should already be familiar with a bitcoin public address like 1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T. Public addresses allow users to receive funds, and private keys allow users to send funds. Here is the corresponding private key for the above public address: 5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS. Some technical details: A bitcoin key is actually an ECDSA public private key pair, which uses the secp256k1 parameter. The curve equation is y^2 = x^3 + 7. In BitcoinJ, a key is represented by the "ECKey". To generate a random key, use the default constructor. The standard toString() allows you to print the public key, and you can use toStringWithPrivate to print the private key: import com.google.bitcoin.core.*;public class MyProgram { public static void main(String[] args) { System.out.println("Hello World!"); ECKey key = new ECKey(); System.out.println("We created key:\n" + key); System.out.println("\n\nHere with private:\n" + key.toStringWithPrivate()); }} Notice that an ECKey key is actually a long hexadecimal string, such as 00956f37ff89dd854922d87b52fd9ec21144b5aa5162e293ebe3c157100dc4eaec . We will convert this into an address later. If you already already have a known private key, you can convert this into an ECKey. You will need to first create a BigInteger from hex. Try running this code: There are multiple bitcoin networks and forks. You can use the same keys on multiple networks, but the addresses generated from those keys will be different. You can identify the main bit Continue reading >>

Java Code Examples Org.bitcoinj.crypto.hdkeyderivation

Java Code Examples Org.bitcoinj.crypto.hdkeyderivation

Project: bitcoin-paper-walletFile: Wallet.java View source code private void init(NetworkParameters params, byte[] seed, String passphrase) { this.params = params; this.seed = seed; strPassphrase = passphrase; byte[] hd_seed = MnemonicCode.toSeed(wordList, ""); dkKey = HDKeyDerivation.createMasterPrivateKey(hd_seed); DeterministicKey dKey = HDKeyDerivation.deriveChildKey(dkKey, 44 | ChildNumber.HARDENED_BIT); dkRoot = HDKeyDerivation.deriveChildKey(dKey, ChildNumber.HARDENED_BIT); int nbAccounts = 1; accounts = new ArrayList(); for(int i = 0; i < nbAccounts; i++) { accounts.add(new Account(params, dkRoot, i)); } strPath = dKey.getPathAsString();} Project: bitcoin-paper-walletFile: Account.java View source code /** * Constructor for account. * * @param NetworkParameters params * @param DeterministicKey mwey deterministic key for this account * @param int child id within the wallet for this account * */public Account(NetworkParameters params, DeterministicKey wKey, int child) { this.params = params; aID = child; // L0PRV & STDVx: private derivation. int childnum = child; childnum |= ChildNumber.HARDENED_BIT; aKey = HDKeyDerivation.deriveChildKey(wKey, childnum); strXPUB = aKey.serializePubB58(params); chains = new ArrayList(); chains.add(new Chain(params, aKey, true)); chains.add(new Chain(params, aKey, false)); strPath = aKey.getPathAsString();} Project: bitcoin-paper-walletFile: Account.java View source code /** * Restore watch-only account deterministic public key from XPUB. * * @return DeterministicKey * */private DeterministicKey createMasterPubKeyFromXPub(String xpubstr) throws AddressFormatException { byte[] xpubBytes = Base58.decodeChecked(xpubstr); ByteBuffer bb = ByteBuffer.wrap(xpubBytes); if(bb.getInt() != 0x0488B21E) { throw new AddressFormatException Continue reading >>

Java Code Examples Org.bitcoinj.core.eckey

Java Code Examples Org.bitcoinj.core.eckey

Project: okwalletFile: DecodePrivateKeyTask.java View source code public final void decodePrivateKey(final BIP38PrivateKey encryptedKey, final String passphrase) { backgroundHandler.post(new Runnable() { @Override public void run() { try { final ECKey decryptedKey = encryptedKey.decrypt(passphrase); // takes time callbackHandler.post(new Runnable() { @Override public void run() { onSuccess(decryptedKey); } }); } catch (final BIP38PrivateKey.BadPassphraseException x) { callbackHandler.post(new Runnable() { @Override public void run() { onBadPassphrase(); } }); } } });} Project: xwalletFile: BitcoinManager.java View source code /** * * @return */@Overridepublic Map getAddressesKeys() { Map addrKeysMap = new HashMap<>(); List allWalletKeys = _coin.getWalletManager().wallet().getImportedKeys(); allWalletKeys.addAll(_coin.getWalletManager().wallet().getIssuedReceiveKeys()); for (ECKey k : allWalletKeys) { Address addr = k.toAddress(Constants.NETWORK_PARAMETERS); String hash = WalletUtils.formatAddress(addr, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE).toString(); addrKeysMap.put(hash, k.getPrivateKeyAsHex()); } return addrKeysMap;} Project: bitnymFile: CLTVScriptPair.java View source code CLTVScriptPair(ECKey newPsynymKey, long expireDate) { ScriptBuilder sb = new ScriptBuilder(); //the part that freezes the tx output, special 5 byte number sb.data(encodeExpireDate(expireDate)); //sb.smallNum(num) sb.op(ScriptOpCodes.OP_CHECKLOCKTIMEVERIFY); sb.op(ScriptOpCodes.OP_DROP); //standard p2pkh part sb.op(ScriptOpCodes.OP_DUP); sb.op(ScriptOpCodes.OP_HASH160); sb.data(newPsynymKey.getPubKeyHash()); sb.op(ScriptOpCodes.OP_EQUALVERIFY); sb.op(ScriptOpCodes.OP_CHECKSIG); this.redeemScript = sb.build(); System.out.prin Continue reading >>

Error Connecting Bitcoinj Client To Multichain

Error Connecting Bitcoinj Client To Multichain

Error connecting BitcoinJ client to Multichain I tried to connect BitcoinJ to Multichain, it showed the following error : 11:34:40 20 PeerGroup$7.run: Starting ... 11:34:40 20 PeerGroup$5.go: Localhost peer detected, trying to use it instead of P2P discovery 11:34:40 20 PeerGroup.connectTo: Attempting connection to [127.0.0.1]:8333 (0 connected, 1 pending, 0 max) 11:34:41 21 NioClientManager.handleKey: Successfully connected to /127.0.0.1:8333 11:34:41 21 Peer.connectionOpened: Announcing to /127.0.0.1:8333 as: /bitcoinj:0.14-SNAPSHOT/Prachakij_Wallet:1.0/ 11:34:41 21 Peer.processVersionMessage: Connected to 127.0.0.1: version=70002, subVer='/Satoshi:0.10.0/', services=0x1, time=2016-04-25 11:34:41, blocks=436 11:34:41 21 PeerGroup.handleNewPeer: [127.0.0.1]:8333: New peer (1 connected, 0 pending, 1 max) 11:34:41 21 PeerGroup.setDownloadPeer: Setting download peer: [127.0.0.1]:8333 11:34:41 21 DownloadProgressTracker.startDownload: Downloading block chain of size 240. 11:34:41 21 Peer.processMessage: [127.0.0.1]:8333: Received unhandled message: [email protected] 11:34:41 21 AbstractBlockChain.add: Block does not connect: 00002b83d7a967cd1897edb2c63ec561579b0142fe53bbbbe7691e7d160b3833 prev 00edb9ee9ccd424ea5a5683e89f419d3bce9eee8ef21f94f26cb7dd133a40abe 11:34:41 21 AbstractBlockChain.add: Block does not connect: 000068f7c1d122ef409da58f57a1e71609977a78d33e7586a36cf7957253c757 prev 00002b83d7a967cd1897edb2c63ec561579b0142fe53bbbbe7691e7d160b3833 11:34:41 21 Peer.blockChainDownloadLocked: blockChainDownloadLocked(00002b83d7a967cd1897edb2c63ec561579b0142fe53bbbbe7691e7d160b3833): ignoring duplicated request: 0000bc237efd32b3e50e24e009f79aa82818ec8875497884228e6e1855a399b4 11:25:05 21 AbstractBlockChain.add: Block does not connect: 000033d25e77bec0 Continue reading >>

Deterministickeychain (bitcoinj 0.12 Api)

Deterministickeychain (bitcoinj 0.12 Api)

public class DeterministicKeyChainextends Object implements EncryptableKeyChain A deterministic key chain is a KeyChain that uses the BIP 32 standard , as implemented by DeterministicHierarchy , to derive all the keys in the keychain from a master seed. This type of wallet is extremely convenient and flexible. Although backing up full wallet files is always a good idea, to recover money only the root seed needs to be preserved and that is a number small enough that it can be written down on paper or, when represented using a BIP 39 MnemonicCode , dictated over the phone (possibly even memorized). Deterministic key chains have other advantages: parts of the key tree can be selectively revealed to allow for auditing, and new public keys can be generated without access to the private keys, yielding a highly secure configuration for web servers which can accept payments into a wallet but not spend from them. This does not work quite how you would expect due to a quirk of elliptic curve mathematics and the techniques used to deal with it. A watching wallet is not instantiated using the public part of the master key as you may imagine. Instead, you need to take the account key (first child of the master key) and provide the public part of that to the watching wallet instead. You can do this by calling getWatchingKey() and then serializing it with DeterministicKey.serializePubB58() . The resulting "xpub..." string encodes sufficient information about the account key to create a watching chain via DeterministicKey.deserializeB58(org.bitcoinj.crypto.DeterministicKey, String) (with null as the first parameter) and then DeterministicKeyChain(org.bitcoinj.crypto.DeterministicKey) . This class builds on DeterministicHierarchy and DeterministicKey by adding support for serialization Continue reading >>

[bitcoin-development] Bitcoinj 0.12

[bitcoin-development] Bitcoinj 0.12

Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Im pleased to announce version 0.12 of bitcoinj, one of the worlds most popular Bitcoin libraries. It is used by at least four Android wallets, three desktop wallets, blockchain.info, Circle, biteasy, CryptoCorp, Lighthouse, BlueMatts relay network, bitpos, countless alt coin wallets, for academic research projects and much more.This release represents 8 months of work. The biggest new feature is HD wallets. Other notable enhancements include a bundled Tor client that can be activated with one line of code, support for multisig wallets, much faster and deterministic ECDSA, many API improvements and big upgrades to the included GUI wallet which can be seen in a new screencasted tutorial.The commit hash of bitcoinj 0.12 is 83a9a71f3fff3f223d0737ad758b519a39dbbd62. New in this releasePrivacy enhancements:Wallets are now hierarchical and deterministic (HD) by default, using the BIP32 specification. Support for mnemonic codes (BIP 39) is also included. Change and receive addresses are no longer being reused. Old wallets are upgraded in place using the private key of the oldest non-rotating key as the seed bytes, so old backups remain valid.Thanks to devrandom, we have an integrated Tor mode using the Orchid library. The user does not have to install the Tor client as its all pure Java. WalletAppKit users can enable usage of Tor with a single line of code. This support should be considered experimental for now.Thanks to Kosta Korenkov, we have an experimental multisig wallets implementation. Multisig (also married) wallets are HD wallets that are connected to a third party risk analysis service or device. When married, the wallet tracks multiple BIP32 key trees, keeps them in sync and starts vending P2SH addresse Continue reading >>

3 Best Bitcoin App Sdk For Ios And Android With Samples

3 Best Bitcoin App Sdk For Ios And Android With Samples

3 best bitcoin app SDK for iOS and Android with samples Bitcoin nowadays is not only a cryptocurrency or a digital payment system. Actually, thanks to its unique features bitcoin has become a real instrument for investment, saving and even earning more money. In this article we want to talk about 3 most popular bitcoin appSDK,thatcan help you to develop your own bitcoin app. Thank their functionality you can create bitcoin wallet, a tool for investors, bitcoin game or any other app connected with this cryptocurrency. Also to check the popularity of analyzed SDKs our team of mobile app developers created three real examples of bitcoin wallets. See them below From 2.9 to 5.8 million people use cryptocurrency wallets in 2017, most of them work with bitcoins. Blockchainis regarded as the most popular bitcoin wallet in the world. Nowadays more than 14 million wallets are registered inBCworldwide. Moreover, Blockchain has a full stack of free APIs for developers, so we start our analysis with it. Supported platforms: Android, iOS, Windows, Mac OS, Linux Blockchainis very popular service. It supports many programming languages in form of libraries for its API (Python, Java, NET, Ruby, PHP, Node etc.). Receive Payments V2API KEY: an easy way for websites to receivepaymentsin bitcoins. This option is completely free and safe. It is ideal for business and personal using. Blockchain WalletAPIKEY: full access to all functions of this service like creating a wallet, making payments, sending transactions, address management and so on. To receive any of the keys one must request API fromBC.The application contains a name of person/organization, e-mail, and URL of the website or app. This process is supposed to exclude different ways of fraud or using keys for unfair purposes. So that Continue reading >>

Java Examples For Org.bitcoinj.wallet.protos.wallet.encryptiontype

Java Examples For Org.bitcoinj.wallet.protos.wallet.encryptiontype

Java Examples for org.bitcoinj.wallet.Protos.Wallet.EncryptionType The following java examples will help you to understand the usage of org.bitcoinj.wallet.Protos.Wallet.EncryptionType. These source code samples are taken from different open source projects. Project: uberpay-wallet-masterFile: SimpleKeyChain.java View source code /*package*/static Protos.Key.Builder serializeEncryptableItem(EncryptableItem item) { Protos.Key.Builder proto = Protos.Key.newBuilder(); if (item.isEncrypted() && item.getEncryptedData() != null) { // The encrypted data can be missing for an "encrypted" key in the case of a deterministic wallet for // which the leaf keys chain to an encrypted parent and rederive their private keys on the fly. In that // case the caller in DeterministicKeyChain will take care of setting the type. EncryptedData data = item.getEncryptedData(); proto.getEncryptedDataBuilder().setEncryptedPrivateKey(ByteString.copyFrom(data.encryptedBytes)).setInitialisationVector(ByteString.copyFrom(data.initialisationVector)); // We don't allow mixing of encryption types at the moment. checkState(item.getEncryptionType() == org.bitcoinj.wallet.Protos.Wallet.EncryptionType.ENCRYPTED_SCRYPT_AES, "We don't allow mixing of encryption types at the moment"); proto.setType(Protos.Key.Type.ENCRYPTED_SCRYPT_AES); } else { final byte[] secret = item.getSecretBytes(); // is expected to be rederived on the fly from its parent. if (secret != null) proto.setSecretBytes(ByteString.copyFrom(secret)); proto.setType(Protos.Key.Type.ORIGINAL); } return proto;} Project: multibit-masterFile: WalletTest.java View source code @Testpublic void encryptionDecryptionBasic() throws Exception { // Check the wallet is initially of WalletType ENCRYPTED. assertTrue("Wallet is not an encrypted wallet", encrypte Continue reading >>

How To Import Private Keys

How To Import Private Keys

Before reading this page, users should note that messing with ECDSA private keys is very dangerous and can result in losing bitcoins, even long after the import.It is recommended that outside of self-generated vanity addresses, users should never import (or export) private keys. [1] [2] As of August 2012, possibly the easiest way to import a private key is using Blockchain.info 's My Wallet service. When successully imported through the "Import/Export" screen, the bitcoins assigned to a private key can be immediately sent to any Bitcoin address. BIPS allows for easy import of private key using Paper Wallet - Import. User can choose to type in the private key manually or scan a QR code containing the private key using the camera. The user must wait 6 confirmations for access to the funds, and system is based on batch importation. Steps described are with the following settings: Use this function if you would like to keep some funds on the paper wallet. Download Mycelium from the Android Play Store or through iTunes. Press the menu button and select "Cold Storage" Press the blue currency tag at the top to toggle currency. After spending, the private key in memory is destroyed so the paper private key remains somewhat secure. Despite this, best practice is to immediately send the remaining balance to a paper wallet that was generated offline. Use this function if you would like to import a private key so all funds are immediately available for spending. Download Mycelium from the Android Play Store or through iTunes. After importing this paper private key, you might consider destroying the original so it cannot be found and your funds stolen. Alternatively, you can keep it safe to be used as an offline backup. If you have Version 7 or later it is now trival. See: How to i Continue reading >>

Wallet (bitcoinj 0.13-snapshot Api)

Wallet (bitcoinj 0.13-snapshot Api)

publicWallet( NetworkParameters params) Creates a new, empty wallet with a randomly chosen seed and no transactions. Make sure to provide for sufficient backup! Any keys will be derived from the seed. If you want to restore a wallet from disk instead, see loadFromFile(java.io.File, org.bitcoinj.core.WalletExtension...) . Creates a new, empty wallet with a randomly chosen seed and no transactions. Make sure to provide for sufficient backup! Any keys will be derived from the seed. If you want to restore a wallet from disk instead, see loadFromFile(java.io.File, org.bitcoinj.core.WalletExtension...) . publicWallet( NetworkParameters params, KeyChainGroup keyChainGroup) publicWallet( Context context, KeyChainGroup keyChainGroup) public static Wallet fromSeed( NetworkParameters params, DeterministicSeed seed) public static Wallet fromWatchingKey( NetworkParameters params, DeterministicKey watchKey, longcreationTimeSeconds) Creates a wallet that tracks payments to and from the HD key hierarchy rooted by the given watching key. A watching key corresponds to account zero in the recommended BIP32 key hierarchy. public static Wallet fromWatchingKey( NetworkParameters params, DeterministicKey watchKey) Creates a wallet that tracks payments to and from the HD key hierarchy rooted by the given watching key. A watching key corresponds to account zero in the recommended BIP32 key hierarchy. public static Wallet fromKeys( NetworkParameters params, List < ECKey >keys) Creates a wallet containing a given set of keys. All further keys will be derived from the oldest key. public DeterministicKey currentKey( KeyChain.KeyPurpose purpose) Returns a key that hasn't been seen in a transaction yet, and which is suitable for displaying in a wallet user interface as "a convenient key to receive f Continue reading >>

How Can I Hardcode A Private Key In Bitcoinj - Eckey Constructor?

How Can I Hardcode A Private Key In Bitcoinj - Eckey Constructor?

how can I hardcode a private key in bitcoinJ - ECKey constructor? Can someone please explain how to use the following constructor (listed here ): ECKey(BigInteger priv, org.spongycastle.math.ec.ECPoint pub) How do I get the big integer representation of it (in other words, and if I understood correctly, is there a function to go from check58 to biginteger?) , and If all you are after is getting an ECKey object for that private key, then Bitcoinj has a DumpedPrivateKey class for just such an occasion. import org.bitcoinj.core.ECKey;import org.bitcoinj.core.DumpedPrivateKey;import org.bitcoinj.params.MainNetParams;public class Example { public static void main(String[] args) { String priv = "L4...5"; ECKey key = DumpedPrivateKey.fromBase58(MainNetParams.get(), priv).getKey(); }} If you would like to use an ECKey constructor explicitly, then you should be able to get the code you need from here: With respect to the constructor you listed, it is a protected constructor, so it's probably not one you would be looking to use. It lists a private key and public key parameters. The private key may be null if the ECKey instance is only going to be used for verifying signatures, not actually producing them. The public key must not be null, and it saves time by not needing to re-compute the public key, which is a CPU intensive operation. Note that most of the public ECKey constructors are deprecated. The preferred way of creating the ECKey objects now is to use the static factory methods. Continue reading >>

Bitcoin Core Development Falling Behind, Warns Bitcoinj's Mike Hearn

Bitcoin Core Development Falling Behind, Warns Bitcoinj's Mike Hearn

Feb 24, 2014 at 05:57 UTC|UpdatedJun 25, 2014 at 17:26 UTC Say what you like about Google, but it isn't an easy place to get hired at. The entrance interviews are notoriously tough, and it is a highly desired employer - which makes Mike Hearn's departure all the more notable. Hearn is an expert in low-level software development, who worked as a site reliability engineer at Google, and focused on account security and antispam. He has also been one of the leading lights in the bitcoin community, heading up the open source development team for bitcoinj , which is the Java implementation of the bitcoin protocol. He is leaving in part because of his growing interest in and commitment to bitcoin. Hearn sees a challenge ahead for the virtual currency: the core development team is shrinking. "The long tail has grown longer, but the heavy lifting and design work has been done by a handful of people. That's quite concerning," says Hearn, highlighting a few key players on the team. He uses the team's page on Github , the open source code repository on which Github is hosted, to see who's most heavily involved. Gavin Andresen, the lead developer, is an obvious mainstay. Others include Philip Kaufmann, who does a lot of GUI development. Wladimir J. van der Laan also works on the front end. "There are occasional fixes and things submitted by other people, but the bulk of the work is being done by Gavin and those guys," says Hearn. "I am a bit concerned by the fact that we don't have a lot of people turning up and doing really serious, useful work on the core." But then, that's a general problem with open source projects. Most people are not paid, meaning that participation can be patchy, and burnout rates can be high. Andresen is paid a salary by the Bitcoin Foundation, and Jeff Gar Continue reading >>

Export Private Keys From Wallet

Export Private Keys From Wallet

Is it possible export the private key corresponding to one of the addresses displayed for my wallet in Bitsquare? I assume that I could in theory generate the keys from the backup seed, but that seems like a very complex solution to something that should be easy. I understand that this is something that needs to be handled carefully and is not a feature suitable for every user, but it is handy for people who know what they are doing. (In my particular case, I would like to fund the wallet using Joinmarkets patient-send functionality. This currently requires knowledge of the recipient private key due to a protocol restriction in Joinmarket, but since the key is mine, it should still be possible to do.) Bitsquare use a HDWallet. I could add such a feature but as you said that should be not accessible in the main screen to avoid that users are doing something weird. Maybe I will add it as a small wallet tool where u can get out a priv key when u enter the address. I agree - such a tool would definitely be very useful for my case, without hurting simplicity of the general UI and without putting users at risk of accidentally doing something bad to their keys. I might even try to build something like this myself (no need to waste your time), just wanted to make sure theres not already a way that Im missing. BTW, is wallet handling with BitcoinJ sufficiently standard that such a tool could be built directly for BitcoinJ itself and be useful for other wallets as well? Or is the actual implementation different for each user of the library (like Bitsquare), such that the tool would need to be specifically aware of Bitsquares implementation? You might find even in BitcoinJ a tool doing that. There are a few command line tools. U need to use the branch we use not the master as tha Continue reading >>

Bitcoin For Beginners, Part 3: The Bitcoinj Api

Bitcoin For Beginners, Part 3: The Bitcoinj Api

Bitcoin for beginners, Part 3: The BitCoinJ API Build a Java-based Bitcoin transaction client Given a public key or its hash you can check whether a matching key pair is in the keychain and retrieve it using the following convenience methods: findKeyFromPubHash(byte[] pubkeyHash)isPubKeyHashMine(byte[] pubkeyHash)findKeyFromPubKey(byte[] pubkey)isPubKeyMine(byte[] pubkey) Note that the only constructor for the Wallet class takes a NetworkParameters object as an argument. This ensures that you cannot mix transactions from the production and test networks in the same wallet. In Listing 3 we default to the testnet (line 13) and declare a Wallet object (line 16) that will later require a File object (line 17) to persist itself to disk. In our main try-catch block, we then initialize the Wallet object to use the testnet (line 20). Next, we loop five times, each time creating a brand-new key pair in the form of an ECKey object, which we add to the wallet (line 26). Having something in our wallet, we then proceed to save it to disk (line 30). If you were to take a look at your file system now, you would see a file named test.wallet. On line 37, we grab the first key in the keychain ArrayList and output it (line 40), followed by the dump of the whole wallet (line 43). Finally, we want to determine whether a particular key has been added to the wallet, so we ask the wallet to compare a given hash to the hashes of the public keys in the wallet (line 47). 001|package com.waferthin.bitcoinj;002|003|import java.io.File;004|import java.io.IOException;005|006|import com.google.bitcoin.core.*;007|008|public class CreateWallet {009|010| public static void main(String[] args) {011|012| // work with testnet013| final NetworkParameters netParams = NetworkParameters.testNet();014|015| // T Continue reading >>

More in litecoin