Starting from:
$30

$24

Homework 5 Solution

The term “mainnet” refers to the actual Bitcoin blockchain network. The term “testnet” is an alternative to mainnet to be used for testing. Testnet coins are separate and distinct from actual bitcoins, and are never supposed to have any value. This allows application developers or bitcoin testers to experiment, without having to use real bitcoins or worrying about breaking the main bitcoin chain. You can obtain testnet coins for free from the faucet at https://testnet.coinfaucet.eu/en/. It is courteous to send the testnet coins back to the faucet after you are done experimenting with them.




Read:



Bitcoin addresses:



https://en.bitcoin.it/wiki/Address



https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses



https://en.bitcoin.it/wiki/List_of_address_prefixes



Base58 encoding: https://en.bitcoin.it/wiki/Base58Check_encoding



Bitcoin address reuse and privacy: https://en.bitcoin.it/wiki/Address_reuse



Testnet: https://en.bitcoin.it/wiki/Testnet



BitcoinJ



https://bitcoinj.github.io/#getting-started



https://bitcoinj.github.io/working-with-transactions



https://bitcoinj.github.io/working-with-the-wallet



Set the hw5.WalletInit.WALLETS_DIR constant to a directory that stores all the wallets.



Read and thoroughly understand hw5.WalletInit.



Run the hw5.WalletInitTest class to create a wallet on testnet. This class will download and sync the testnet block chain on to your computer and thus may take a few minutes. Skim through the logging output to get a basic understanding of what’s happening. Submit the current receive address of your wallet as your solution to question 4 in a text file called homework5solutions.txt.



Use the testnet faucet to send testnet coins to the testnet wallet’s receive address. Look up the transaction ID at the testnet blockchain explorer at https://www.blocktrail.com/tBTC to see if the transaction was submitted to the network. Be sure to receive at least one confirmation in case a double-spend attack prevented you from receiving the coins. The faucet may send the same coin to you in multiple different transactions, so the blockchain explorer may tell you that the coin has been double-spent. To find the actual transaction that successfully sent you coins, run the WalletInitTest and watch the WalletInitTest.monitor method’s periodic reporting of the transactions it receives from its peers. The output will tell you which transaction succeeded and which is dead. Submit the transaction ID and the amount of testnet coins sent to your receive address as your solution to question 5 in homework5solutions.txt. Answer the following questions: how many outputs does the transaction have? What is the purpose of the output that locks coins to the address that’s not yours?



Run the hw5.WalletInitTest class again to update your wallet’s blockchain and confirm that it contains the amount given to you in question 3.
Use BitcoinJ to write a custom Bitcoin address generator for mainnet. Place your implementation in the method CustomAddressGenerator.get(String). This method has one parameter which is a string called prefix encoded in base58. The method returns a bitcoin address on mainnet that begins with 1 followed by prefix. Submit your CustomAddressGenerator class.



Use the CustomAddressGenerator.get(String) method to generate a mainnet address that begins with 1 followed by the first four letters of your last name in uppercase. If your last name is shorter than four letters, append as many “X” characters as necessary. If the first four letters of your last name in uppercase includes a letter not allowed in a Bitcoin address, then use “X” instead of the letter. Submit your custom bitcoin address as your solution to question 8 in a text file called homework5solutions.txt.

More products