-
Notifications
You must be signed in to change notification settings - Fork 5
Mining
Ngind is three-in-one : node of global ngin network, wallet and miner
You can make solo block mining with ngind node or download Miner binaries and mine by pool. Also you can download Wallet binaries with GUI version
At first we need to run ngind and create our wallet on which we will get mining rewards
Step 1. Downloading ngind daemon/wallet and creating wallet number
Download ngind according to your operating system from here - https://github.com/NginProject/ngind/releases and unpack it
From CMD, PowerShell or your preferred console, go to the route where you stored ngind.exe.
Let’s say you stored ngin.exe in the recommended directory *$HOME\AppData\Roaming\Ngin/* <~ where $home is your C:\Users\UserName path
Input the following command: cd c:\users\UserName\AppData\Roaming\Ngin and hit enter
Once you’re there, you can write all the commands that ngind.exe can execute!
Now we need to run console command, which create wallet in ngin network. Run from console:
ngind.exe account new
For example you unpack it to /opt/ngind/
in linux shell go to this folder by command cd /opt/ngind/ run command from linux shell in this folder:
./ngind account new
Result of command same for windows and linux , you will be prompted for password (enter it and save it in safe place!) and you will see you account wallet number:
Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {918e173c8426593bd37d5bc7d03f17dcc154cd5b}
So 918e173c8426593bd37d5bc7d03f17dcc154cd5b is your wallet number.
Step 2. Running ngind daemon/wallet console
Run command
ngin console (on Linux)
or
ngind.exe console (Windows )
From same dir you stored ngind binary
You will see initial screen from ngin.network and console prompt like
2018-10-07 21:40:54 ngind version: v0.1.1 2018-10-07 21:40:54 Blockchain: Ngin Mainnet 2018-10-07 21:40:54 Chain database: /root/.ngin/mainnet/chaindata ..... coinbase: 0x918e173c8426593bd37d5bc7d03f17dcc154cd5b at block: 19154 (Sun, 7 Oct 2018 12:19:30 EEST) datadir: /root/.ngin/mainnet modules: admin:1.0 debug:1.0 ngin:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
>
So in this console you can run all commands to communicate with ngin network.
For example:
> ngin.coinbase "0x918e173c8426593bd37d5bc7d03f17dcc154cd5b"
will show you your based wallet number in system
web3.fromWei(ngin.getBalance(ngin.coinbase), "ether")
0
Will show your actual balance of your wallet, currently its 0 , but we will mine and it will grow up
Step 3. Mining
Mining is math process of confirmation next block with transactions in system. Approximately new block in ngin created every 10 minutes. Its no need to know much more even previous information to get money to wallet by mining :)
CPU Mining with Ngins
NOTE: Ensure your blockchain is fully synchronised with the main chain before starting to mine, otherwise you will not be mining on the main chain.
When you start up your ngin node with ngind it is not mining by default. To start it in mining mode, you use the --mine command line option. The -minerthreads parameter can be used to set the number parallel mining threads (defaulting to the total number of processor cores).
ngind --mine --minerthreads=4
You can also start and stop CPU mining at runtime using the console. miner.start takes an optional parameter for the number of miner threads.
> miner.start(8)
true
> miner.stop()
true
Note that mining for Ngins only makes sense if you are in sync with the network (since you mine on top of the consensus block). Therefore the ngin 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 Ngins 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 ngin--mine will not start up.
You can set your etherbase on the command line:
ngin --etherbase 1 --mine 2>> ngin.log // 1 is index: second account by creation order OR ngin --etherbase '0xa4d8e9cae4d04b093aac82e6cd355b6b963fb7ff' --mine 2>> ngin.log
You can reset your etherbase on the console too:
miner.setEtherbase(ngin.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 (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("|\|(_+!|\|")
...
debug.printBlock(131805) BLOCK(be465b020fdbedc4063756f0912b5a89bbb4735bd1d1df84363e05ade0195cb1): Size: 531.00 B TD: 643485290485 { NoNonce: ee48752c3a0bfe3d85339451a5f3f411c21c8170353e450985e1faab0a9ac4cc Header: [ ... Coinbase: a4d8e9cae4d04b093aac82e6cd355b6b963fb7ff Number: 131805 Extra: |\|(_+!|\| ... }
See also this proposal
You can check your hashrate with miner.hashrate, the result is in H/s (Hash operations per second).
> miner.hashrate 712000
After you successfully mined some blocks, you can check the Ngins balance of your etherbase account. Now assuming your etherbase is a local account:
> ngin.getBalance(ngin.coinbase).toNumber(); '34698870000000'
In order to spend your earnings on gas to transact, you will need to have this account unlocked.
> personal.unlockAccount(ngin.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) { addrs = []; if (!addr) { addr = ngin.coinbase } limit = ngin.blockNumber - lastn for (i = ngin.blockNumber; i >= limit; i--) { if (ngin.getBlock(i).miner == addr) { addrs.push(i) } } 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, ngin.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.
The logs show locally mined blocks confirmed after 5 blocks. At the moment you may find it easier and faster to generate the list of your mined blocks from these logs.
Mining success depends on the set block difficulty. Block difficulty dynamically adjusts each block in order to regulate the network hashing power to produce a 10 second blocktime. Your chances of finding a block therefore follows from your hashrate relative to difficulty. The time you need to wait you are expected to find a block can be estimated with the following code:
INCORRECT...CHECKING
etm = ngin.getBlock("latest").difficulty/miner.hashrate; // estimated time in seconds Math.floor(etm / 3600.) + "h " + Math.floor((etm % 3600)/60) + "m " + Math.floor(etm % 60) + "s"; // 1h 3m 30s
Given a difficulty of 3 billion, a typical CPU with 800KH/s is expected to find a block every ....?