How to claim and sell your Bitcoin Cash

On Tuesday August 1st, Bitcoin Cash forked from Bitcoin, and every Bitcoin holder is eager to claim their free BCH. So here is the short and painless way to do it.

In short, what we’re going to do is:

  1. Secure your Bitcoin by transferring it away to a new (paper-) wallet
  2. Sweep your private keys in Electron Cash to a new BCH address
  3. Sell your BCH

Secure your Bitcoin

So, the first thing you want to do is to secure your existing Bitcoin – in case anything goes wrong while handling your private keys, your existing Bitcoin will be safe.

I did this by creating a paper wallet on bitaddress.org as described in my earlier article; then I transferred all my BTC to that wallet. Store it in a safe place.

Obtain your private keys

Next, you need your private keys in order to sweep them on the BCH chain. I run a bitcoind, the way to do this is to unlock your wallet and then dump it:

$  bitcoin-cli walletpassphrase "xxx" 60
$ bitcoin-cli dumpwallet wallet.txt

Note the extra space before the walletpassphrase command; this will tell your bash to not write the command to the command history, thereby keeping your passphrase a secret.

This will dump all your private keys in wallet.txt. You can reduce this to just the keys like this:

$ cut -f1 -d' ' <wallet.txt >keys.txt

Now you got your keys.

Sweep your private keys

Next, install Electron Cash. You are going to enter your private keys there, so be sure you got the right version.. apparently there were scams, that’s your own responsibility.

On startup, it prompts you to create a new wallet. Save the passphrases in a secure location. Once Electron Cash is up and running, go to Wallet -> Private Keys -> Sweep and paste all your private keys from your keys.txt file there.

Potentially you have many more keys. Press “sweep”. If you have many keys, this will now take some time, maybe one or two minutes, while the GUI appears to do nothing. Then, a transaction window pops up. Here, you click “broadcast” in order to broadcast your transaction. This will transfer all your BCH to your new Electron Cash wallet.

Now you have to wait until the transaction is confirmed.

Sell your BCH

You can now transfer and sell your BCH on any exchange that supports it. I use shapeshift.io.

Hope that was helpful.

How to Send and Check Balance of ERC20 Tokens Using geth

So, you got some standard ERC20 token from wherever, be it a popular one like Golem (GNT) or a more obscure one like the infamous yet entirely unknown Kekel, and you want to check your balance. How do you do that? Mist offers a simple UI for that, but when you are a real crack, you are of course using only geth console. Here’s what you need.

Checking Token Balance – Basic Way

You’re going to need three things:

  1. The token contract address
  2. Your account address
  3. The token contract’s ABI

You need to figure out the first two yourself. You can use a generic ABI to check token balance. We instantiate the contract ABI as follows:

> var tokenContract = eth.contract([{
     "type":"function",
     "name":"balanceOf",
     "constant":true,
     "payable":false,
     "inputs":[{"name":"","type":"address"}],
     "outputs":[{"name":"","type":"uint256","value":"0"}]
}]);

Now we have the contract’s interface. Next we use it to check our balance. The following example will show my account’s Golem balance:

> var golemContractAddress = "0xa74476443119A942dE498590Fe1f2454d7D4aC0d";
> var account = "0x27f8a692b3c8279fce29f2629b8d87ac717300f8";
> tokenContract.at(golemContractAddress).balanceOf(account);
678633655750000000000

This outputs the token balance in plain tokens, i.e. without showing a decimal point.



 

Human Standard Token ABI

For a more thorough solution, I found the Human Standard Token ABI by Dan Finley on github. It is a node.js module which provides an API to standard tokens. I changed it a little so I can run it from the geth console. Install token.js in a local folder on the machine where you run geth, such as /home/user/geth/token.js, and run the geth console with

geth console --preload /home/user/geth/token.js

Now you have the full functionality of a token contracts in the variable “tokenContract”:

> var golemContractAddress = "0xa74476443119A942dE498590Fe1f2454d7D4aC0d";
> var account = "0x27f8a692b3c8279fce29f2629b8d87ac717300f8";
> var golem = tokenContract.at(golemContractAddress);
> golem.symbol();
"GNT"
> golem.name();
"Golem Network Token"
> golem.balanceOf(account);
678633655750000000000
> golem.decimals()
18

The ABI also supports sending tokens as follows:

var value = '100' // Base 10, accounts for decimals.
golem.transfer(toAddress, value, { from: addr }, function (err, txHash) {
  if (err) console.error(err)

  if (txHash) {
    console.log('Transaction sent')
    console.dir(txHash)
  }
})

Please refer to the readme on github.

I hope this was helpful and wish you a nice day 🙂