Saturday, November 30, 2013

Crypto Currency Experiments

I have become interested in Bitcoin lately and have been studying it. I searched around to see if there was a way to run it in a test environment and came across testnet-in-a-box. I got this environment up and running using CPUminer as a mining tool. However after running the CPUminer for a while and doing some additional reading, I became concerned about how long it would take to complete my first block. Here is the output of CPUminer running against my Litecoin environment (more on that later).

Notice that my hash performance is between 2 to 3 kiloHashes per second. I looked at a couple of the mining calculators HERE and HERE and found I would need to wait more than two weeks! This was even with the difficulty for the bitcoin environment set to 1. As you read about bitcoin mining you find it requires special hardware that can deliver millions or billions of hashes per second performance. I came across Litecoin which is based on bitcoin but has several differences, one of which mining can still be done with CPUs. Even with the difficulty in the Litecoin environment set to 0.00024414 it took about 5-7 minutes per block. This test environment begins with nothing except the Genesis Block. The coins that are mined do not mature until you processed about 120 blocks. Which for me was about 12 hours (I was also using my computer for other things so the hash rate gets impacted). After you have some coins you can do transactions and study the system to see how it reacts, etc.

The following is a simple HOWTO to get an environment like this up and running without all the research I had to do. This was done on Windows but you could do it under Linux as well or better.

A.) Get litecoin-0.6.3c-win32  HERE (32 bit version, I did not see a 64 bit version)
B.) Get pooler-cpuminer-2.3.2-win32/64 HERE (either the 32 bit or 64 bit version for windows)
C.) Get the Litecoin testnet-box ZIP file -click button on far right side "Download ZIP"

These are all ZIP packages so you just need to extract A and B into a folder of its own and extract the testnet ZIP into the Litecoin daemon folder. That process will place two folders in the daemon folder named "1" and "2". In the 1 and 2 folders is just a .conf file. Next run the following commands:

1.) Open a command window (cmd) or use Cygwin Terminal (Unix like feel on Windows).
2.) Change directory to the folder where you have Litecoin and get into the daemon folder.
3.) Type litecoind -datadir=1 -daemon and press enter. It will just sit there as it runs and the command prompt will not return.
4.) Open another command window and change directory to the same place as step 2 above.
5.) Type litecoind -datadir=2 -daemon and press enter. Notice the data directory in step 3 is "1" and in this step it is "2".
6.) Open another (the third) command widow and change directory the same place as 2 above.
7.) Type litecoind -datadir=1 getinfo then litecoind -datadir=2 getinfo

You should see something like this as output for each node:

{
    "version" : 60300,
    "protocolversion" : 60001,
    "walletversion" : 60000,
    "balance" : 3036.70000000,
    "blocks" : 183,
    "connections" : 1,
    "proxy" : "",
    "difficulty" : 0.00024414,
    "testnet" : true,
    "keypoololdest" : 1385777419,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "mininput" : 0.00010000,
    "errors" : ""
}

Your balance will be zero along with your blocks but it should look similar if all is well. By changing the datadir from 1 to 2 you are checking each node. Now that these are running you are ready to start mining.

8.) Open another command window (the fourth)
9.) Change directory to the CPUminer folder
10.) Type minerd -a scrypt -o http://127.0.0.1:19334 -O testnet:testnet

If all goes well you should see an output similar to the picture at the beginning of the post. The miner will continue to output its current hash rate and when it completes a block you will see the (yay!!!) like above. Remember you will need to wait until you process 120 blocks before your coins stack up.

After that you will want to experiment with the system. That can be done using the third command window. The third command window can control your two nodes. Here is my cheat-sheet:

Stop node 1 ---> litecoind -datadir=1 stop just up arrow to re-run in window 1
Stop node 2 ---> litecoind -datadir=2 stop just up arrow to re-run in window 2
Create Addr---> litecoind -datadir=1 getnewaddress  <name> create a public address on node 1
Create Addr---> litecoind -datadir=2 getnewaddress  <name> create a public address on node 2
Send Coins  ---> litecoind -datadir=1 sendtoaddress <address> <amount> send from 1 to addr
Send Coins  ---> litecoind -datadir=2 sendtoaddress <address> <amount> send from 2 to addr
Balance        ---> litecoind -datadir=1 getbalance  will show how many coins node 1 has
Transactions ---> litecoind -datadir=1 listtransactions  will show you node 1 transactions
Find Addr    ---> litecoind -datadir=1 getaddressesbyaccount <accountname>
Help             ---> litecoind -datadir=1 help


The help output will show you the many other commands (explore!!!)

addmultisigaddress <nrequired> <'["key","key"]'> [account]
backupwallet <destination>
dumpprivkey <litecoinaddress>
encryptwallet <passphrase>
getaccount <litecoinaddress>
getaccountaddress <account>
getaddressesbyaccount <account>
getbalance [account] [minconf=1]
getblock <hash> [decompositions]
getblockcount
getblockhash <index>
getconnectioncount
getdifficulty
getgenerate
gethashespersec
getinfo
getmemorypool [data]
getmininginfo
getnetworkhashps [blocks]
getnewaddress [account]
getpeerinfo
getrawmempool
getreceivedbyaccount <account> [minconf=1]
getreceivedbyaddress <litecoinaddress> [minconf=1]
gettransaction <txid> [decompositions]
getwork [data]
getworkex [data, coinbase]
help [command]
importprivkey <litecoinprivkey> [label]
keypoolrefill
listaccounts [minconf=1]
listreceivedbyaccount [minconf=1] [includeempty=false]
listreceivedbyaddress [minconf=1] [includeempty=false]
listsinceblock [blockhash] [target-confirmations]
listtransactions [account] [count=10] [from=0]
move <fromaccount> <toaccount> <amount> [minconf=1] [comment]
sendfrom <fromaccount> <tolitecoinaddress> <amount> [minconf=1] [comment] [comment-to]
sendmany <fromaccount> {address:amount,...} [minconf=1] [comment]
sendrawtx <hex string>
sendtoaddress <litecoinaddress> <amount> [comment] [comment-to]
setaccount <litecoinaddress> <account>
setgenerate <generate> [genproclimit]
setmininput <amount>
settxfee <amount>
signmessage <litecoinaddress> <message>
stop
validateaddress <litecoinaddress>

verifymessage <litecoinaddress> <signature> <message>

As a final bit of fun, if you want to see how the GUI client works, you can use that in place of node 2. I recommend to just stop node 2 using command window 3, then with a new command window change directory to the litecoin folder and this time instead of going into the daemon folder, stay at the root where you will see the litecoin-qt.exe file, and type:

litecoin-qt -datadir=daemon/2

This will launch the GUI client for node 2. You can now send coins from here to node 1 based on the addresses you created with the getnewaddress commands. You will notice that if you stop either node the mining will fail but keep trying, once you have 2 nodes in the system it will begin mining again (2 is the minimum).


Note, it is a good idea to specify an account name every time you create a new address that way you can start up later and figure out the addresses. Example:

> litecoind -datadir=1 getnewaddress BOB1          # This creates a new address with the name BOB1
n2V4d59G3LcjE5734JiW74rKKRjEmLissk

> litecoind -datadir=1 getnewaddress BOB2          # This ones name is BOB2
mgtmpeVtiwLfP8pGHf94ivZTej5XsefLAv

> litecoind -datadir=1 listaccounts                            # shows the coins in each account
{
    "" : 4336.70000000,
    "BOB1" : 0.00000000,
    "BOB2" : 0.00000000
}

> litecoind -datadir=1 getaddressesbyaccount BOB1          # This returns the public address for BOB1
[
    "n2V4d59G3LcjE5734JiW74rKKRjEmLissk"
]

> litecoind -datadir=1 getaddressesbyaccount BOB2          # This returns the public address for BOB2
[
    "mgtmpeVtiwLfP8pGHf94ivZTej5XsefLAv"
]

Have fun!

1 comment: