Dean

neucoin-qt-walletWhen you are using Proof of Stake (PoS) coins, active coin control is essential to ensuring that you maximize your PoS rewards. If you do not use coin control you may benefit less from compounding of your rewards, and you may lose more rewards than necessary when you make a payment from your wallet.

Exactly how much difference this makes will depend on the specifications of the coin itself, and what transactions you make. It is particularly important for coins such as Neucoin, in which small and medium sized holders must wait a long time between each time they stake and get a reward.

Some wallets will have coin control functions within the graphical user interface (GUI), which makes things easier, but some do not. This article presents a manual method of coin control for users of Qt wallets which do not have a these features within the GUI. It is especially focused on Neucoin, but the same commands should work in any Qt wallet.

Why You Need to Use Coin Control

As I already stated, small and medium sized Neucoin holders must wait a long time before they stake. When you do finally get to stake some coins, you do not get the interest due on your whole balance; instead, one of the payments you have received is selected and you earn the rewards due on that amount. The rest of your interest is not lost, it keeps building up and you get it later. But what this means is that if you receive a single payment for 10,000 coins, for example, you will earn more compound interest than if you receive 10 payments for 1,000 coins, even though your balance is the same. This is because in both cases you will wait the same amount of time before getting your first reward, but in the first instance you will receive all of your interest at once, whereas in the second example you will receive only 10% as much on your first stake. Because you can earn PoS rewards on your PoS rewards (compounding) that means you will eventually end up with more money in the first example when you got a single payment than you would in the second example where you got 10 payments that added up to the same amount.

In the example above you could easily fix this without getting into any advanced techniques simply by using your wallet in the ordinary way to send yourself 10,000 coins. By doing this you would combine all of the outputs – all 10 of the 1,000 Neucoin payments – into a single output. But sometimes things can be a little more complicated. For example, lets say you receive a single payment of 10,000 coins, and leave it in your wallet to stake. After 8 weeks you still haven’t earned your first reward, but have built up a nice bit of ‘interest owed’ on these coins. You now receive those 10 payments for 1,000 each we looked at before. When you spend any coins in your wallet, you lose the unpaid rewards owed to you for staking them. So in this example you would want to send a 10,000 Neucoin payment to yourself using these 10 new payments. But if you simply use the wallet as normal to send a payment to yourself it will probably not do this – it will use the 10,000 you got in your first deposit, destroying your earned rewards and doing nothing to consolidate the smaller payments. To do this, you need to be able to specify which outputs (which payments received) you want to use to create your transaction; that is what I am going to show you how to accomplish in this guide.

Coin control can also be useful when sending payments from your wallet. By specifying which outputs to use in order to make a payment you can ensure that you are not losing rewards unnecessarily. Please be aware, however, that when sending payments to somebody else you will probably need to send yourself change because each output is used entirely in each transaction. I will explain this properlylater on in the guide, but for now just be aware that if you don’t do this you may lose some of your coins.

Manual Coin Control Using the Qt Wallet Console

Manual coin control requires you to use the console rather than the GUI. That means instead of just selecting options from menus, you have to manually type commands. These commands must be precise and use the correct grammar or they won’t work, so please read the instructions carefully and check that you have typed each command correctly before hitting enter.

To open a console window you just need to click ‘Help’ from the navigation menu of your wallet, then select ‘Debug Window’. This will open up a new window with two tabs: click ‘console’ to get to the tab that we are going to use here.

Step One: List Unspent Outputs

In your console window type “listunspent” (without the quotation marks) and hit enter. This will give you a list of all the outputs of previous transactions which belong to you, or in more plain language, all of the payments that you have received.

Each one will appear between curly brackets and should look something like this:

{

"txid" : "a long list of random looking characters should be here",

"vout" : "this should be a number",

"address" : "this is the Neucoin address belonging to you that these coins where sent to",

"account" : "",

"scriptPubKey" : "another long list of random looking characters",

"amount" : "the number of coins you received",

"confirmations" : "the number of confirmations for this transaction"

}

You can use this list to select the outputs you want to use to make a payment. For example, Neucoin owners may want to select smaller and newer outputs (newer outputs will have fewer confirmations) and leave any older and larger ones.

When you have chosen which ones you want to use, make a note of the exact “amount” for each one. If you have received coins with more than one address then you will also need a list of the each address that appears in one of the outputs you are going to use.

Once you have made a note of these things separately, we only need the “txid”, “vout” and “scriptPubKey” to put into the next step. You may like to copy and paste each one into a text editor and then delete the every line apart from those three, to leave something like this:

{

"txid" : "a long list of random looking characters should be here",

"vout" : "this should be a number",

"scriptPubKey" : "another long list of random looking characters"

}

Notice that I have removed the comma from the end of the “scriptPubKey” line. Commas must always be included at the end of each line, apart from the last one. This is one of those annoying grammar things that you have to get right (and which I personally mess up more often than not). Don’t worry too much, if you get this kind of thing wrong you won’t lose any coins, it just won’t accept the command. Also please note that if you are not a programmer then you officially will be after you’ve done this, so feel free to be a bit proud of yourself.

Creating a Raw Transaction

The next step is to use the outputs we have selected to build the code for a complete transaction.

You should have a list of edited outputs from the last section. Put them, complete with brackets, into the command below:

createrawtransaction '[output1, output2]' '{"address you want to send coins to" : number of coins to send}'

The number of coins you are sending must be exactly equal to total of all the outputs you have used minus the transaction fee (0.01). It is very important that you get this right as you could lose coins if you make a mistake here. For example, if you have one output with an amount of 1,000 and another with an amount of 2,000 then you must send 2999.99 coins (1000+2000-0.01). If you were to make a mistake and send just 2,000 coins, then you would end up paying a fee of 1,000 coins that you would never see again.

To give you an idea of what this should look you can see an example of a raw bitcoin transaction taken from this Reddit thread below:

createrawtransaction '[{"txid":"c7e5e03d2ab5458819eedec46d0ba38ca7a6525e38b493073277cf4a1550a348","vout":1,"scriptPubKey":"76a9144a06df74729aef1dce5e4641960da3a439d2460b88ac"},{"txid":"c7e5e03d2ab5458819eedec46d0ba38ca7a6525e38b493073277cf4a1550a348","vout":0,"scriptPubKey":"76a914f88262828f5e64b454249e4c45ddb6071a2ab0a988ac"}]' '{"mty3qVvYyggQJnYfaXupbHRAPVhUxr1vso":0.17543376,"mwzkF4gP1xRoFKA4YvJpNFR9qvYzaWrFaE":0.17543375}'

Neucoin and most other altcoins will use the exact same format. In this example you can hopefully see that two addresses are listed to send coins to, with an amount for each one and a comma between them. If you are manually creating a transaction to send coins to somebody else then you will probably need to do this, because you will probably need to select outputs which add up to more than the amount you want to send, and then send the change to yourself. For example, you may have outputs of 10 and 15, but you want to send 20 coins – so you need to send the remaining 5 to your own address, otherwise they will be added to the transaction fee and lost.

When you have pasted this command into the console and hit enter, if you have managed to get all the grammar right, then you will get a long list of random looking characters as a response. This is your ‘raw transaction hex code’. Copy this for use in the next step.

Signing Your Transaction

You now need to sign your transaction with the private keys of all addresses used in the outputs you chose earlier. You can find your private key for any address using the following console command:

dumpprivkey <address>

Obviously you should replace <address> with the public address you want to get the private key for. If you have encrypted your wallet then you will need to unlock it before doing this.

You can now sign your raw transaction using the following command:

signrawtransaction 'your hex code generated in the last step' '[output1, output2]' '["privatekeyone", "privatekeytwoifneeded"]'

The middle section with output1 and output2 should be exactly the same as you used in the last step when you created the raw transaction.

When you hit the enter button on that command you will get a new, signed hex code. Copy and paste that into the final command:

Sending Your Transaction

The last bit is easy:

sendrawtransaction 'your signed hex code'

When you hit enter on that final command your transaction will be broadcast to the network and your console will reply with a transaction id. If you have used this to send coins to yourself in order to consolidate smaller payments for staking, then your wallet GUI should now show ‘payment to yourself -0.01’.

Neucoin Tips Accepted! NXh4z6DVg4EA8t5veRUrn58YcFnfrrXXKk