# What is CPU Mining?

You can use your computer’s central processing unit (CPU) to mine expanse. This is no longer profitable, since GPU miners are roughly two orders of magnitude more efficient. However, you can use CPU mining to mine on the Morden testnet or a private chain for the purposes of creating the expanse you need to test contracts and transactions without spending your real expanse on the live network.

**Note:** The testnet expanse has no value other than using it for testing purposes (see [Test Networks](http://docs.expanse.tech/en/latest/network/test-networks.html#test-networks)).

#### **USING GEXP** <a href="#using-gexp" id="using-gexp"></a>

When you start up your expanse node with gexp it is not mining by default. To start it in CPU mining mode, you use the –mine [command line option](https://github.com/expanse-org/go-expanse/wiki/Command-Line-Options). The -minerthreadsparameter can be used to set the number parallel mining threads (defaulting to the total number of processor cores).

gexp –mine –minerthreads=4

You can also start and stop CPU mining at runtime using the [console](https://github.com/expanse-org/go-expanse/wiki/JavaScript-Console#adminminerstart). miner.start takes an optional parameter for the number of miner threads.

\> miner.start(8)\
true\
\> miner.stop()\
true

Note that mining for real expanse only makes sense if you are in sync with the network (since you mine on top of the consensus block). Therefore the exp blockchain downloader/synchroniser will delay mining until syncing is complete, and after that mining automatically starts unless you cancel your intention with miner.stop().

In order to earn expanse you must have your **etherbase** (or **coinbase**) address set. This etherbase defaults to your primary account. If you don’t have an etherbase address, then gexp –mine will not start up.

You can set your etherbase on the command line:

gexp –etherbase 1 –mine  2>> gexp.log // 1 is index: second account by creation order OR\
gexp –etherbase ‘0xa4d8e9cae4d04b093aac82e6cd355b6b963fb7ff’ –mine 2>> gexp.log

You can reset your etherbase on the console too:

miner.setEtherbase(exp.accounts\[2])

Note that your etherbase does not need to be an address of a local account, just an existing one.

There is an option [to add extra Data](https://github.com/expanse-org/go-expanse/wiki/JavaScript-Console#minersetextra) (32 bytes only) to your mined blocks. By convention this is interpreted as a unicode string, so you can set your short vanity tag.

miner.setExtra(“BORDERLESS”)\
…\
debug.printBlock(131805)\
BLOCK(be465b020fdbedc4063756f0912b5a89bbb4735bd1d1df84363e05ade0195cb1): Size: 531.00 B TD: [643485290485](tel:643485290485) {\
NoNonce: ee48752c3a0bfe3d85339451a5f3f411c21c8170353e450985e1faab0a9ac4cc\
Header:\
\[\
…\
&#x20;      Coinbase:           a4d8e9cae4d04b093aac82e6cd355b6b963fb7ff\
&#x20;      Number:            131805\
&#x20;      Extra:            ΞTHΞЯSPHΞЯΞ\
…\
}

You can check your hashrate with [miner.hashrate](https://github.com/expanse-org/go-expanse/wiki/JavaScript-Console#adminminerhashrate), the result is in H/s (Hash operations per second).

**>** miner.hashrate\
712000

After you successfully mined some blocks, you can check the expanse balance of your etherbase account. Now assuming your etherbase is a local account:

**>** exp.getBalance(exp.coinbase).toNumber();\
‘34698870000000’

In order to spend your earnings on gas to transact, you will need to have this account unlocked.

**>** personal.unlockAccount(exp.coinbase)\
Password\
**true**

You can check which blocks are mined by a particular miner (address) with the following code snippet on the console:

**function** minedBlocks(lastn, addr) {\
&#x20;addrs **=** \[];\
&#x20;**if** (**!**&#x61;ddr) {\
&#x20;  addr **=** exp.coinbase\
&#x20;}\
&#x20;limit **=** exp.blockNumber **–** lastn\
&#x20;**for** (i **=** exp.blockNumber; i **>=** limit; &#x69;**—**) {\
&#x20;  **if** (exp.getBlock(i).miner **==** addr) {\
&#x20;    addrs.push(i)\
&#x20;  }\
&#x20;}\
&#x20;**return** addrs\
}\
// scans the last 1000 blocks and returns the blocknumbers of blocks mined by your coinbase\
// (more precisely blocks the mining reward for which is sent to your coinbase).\
minedBlocks(1000, exp.coinbase);\
//\[352708, 352655, 352559]

Note that it will happen often that you find a block yet it never makes it to the canonical chain. This means when you locally include your mined block, the current state will show the mining reward credited to your account, however, after a while, the better chain is discovered and we switch to a chain in which your block is not included and therefore no mining reward is credited. Therefore it is quite possible that as a miner monitoring their coinbase balance will find that it may fluctuate quite a bit.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.expanse.tech/miner/what-is-cpu-mining.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
