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!

How do you make a key?

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:

" + key); System.out.println("



Here with private:

" + 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: