> miner.start()
> null
before it , I had created a account like this .
user1 = eth.accounts[0]
"0xb62f0bae52d153365661c4e23ab1d594484e9bef"
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this community> miner.start()
> null
before it , I had created a account like this .
user1 = eth.accounts[0]
"0xb62f0bae52d153365661c4e23ab1d594484e9bef"
Recently, there are so many people confused about miner.start(1)
returning null, but it's actually not a problem, just a reasonable return value misunderstanding. If you aren't sure that your node is mining, please execute eth.hashrate
to check, if the return value is greater than zero, it is mining, otherwise, it is not.
Now let's analyze why miner.start(1)
returns null. It might help to read the source code. When you execute the command miner.start(1)
on the terminal, this would call Start(threads *int)
method in api.go source file, as follows:
// Start the miner with the given number of threads. If threads is nil the number
// of workers started is equal to the number of logical CPUs that are usable by
// this process. If mining is already running, this method adjust the number of
// threads allowed to use.
func (api *PrivateMinerAPI) Start(threads *int) error {
// Set the number of threads if the seal engine supports it
if threads == nil {
threads = new(int)
} else if *threads == 0 {
*threads = -1 // Disable the miner from within
}
type threaded interface {
SetThreads(threads int)
}
if th, ok := api.e.engine.(threaded); ok {
log.Info("Updated mining threads", "threads", *threads)
th.SetThreads(*threads)
}
// Start the miner and return
if !api.e.IsMining() {
// Propagate the initial price point to the transaction pool
api.e.lock.RLock()
price := api.e.gasPrice
api.e.lock.RUnlock()
api.e.txPool.SetGasPrice(price)
return api.e.StartMining(true)
}
return nil
}
As the miner is not currently mining, api.e.IsMining()
returns false, and then executes api.e.StartMining(true)
function and returns its return value. Now let's read its implementation, as follows:
func (s *Ethereum) StartMining(local bool) error {
eb, err := s.Etherbase()
if err != nil {
log.Error("Cannot start mining without etherbase", "err", err)
return fmt.Errorf("etherbase missing: %v", err)
}
if clique, ok := s.engine.(*clique.Clique); ok {
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
if wallet == nil || err != nil {
log.Error("Etherbase account unavailable locally", "err", err)
return fmt.Errorf("singer missing: %v", err)
}
clique.Authorize(eb, wallet.SignHash)
}
if local {
// If local (CPU) mining is started, we can disable the transaction rejection
// mechanism introduced to speed sync times. CPU mining on mainnet is ludicrous
// so noone will ever hit this path, whereas marking sync done on CPU mining
// will ensure that private networks work in single miner mode too.
atomic.StoreUint32(&s.protocolManager.acceptTxs, 1)
}
go s.miner.Start(eb)
return nil
}
Please notice the return value of StartMining(local bool)
method.It would return nil
if the start mining process is successful, or return a detailed error message otherwise. So it's a frustrating return value, but it doesn't mean that the start mining process failed.
Hope it helps~
try setting miner.setEtherbase(eth.coinbase)
or step by step:
geth attach
miner.setEtherbase(eth.accounts[0])
miner.start()
Even if it returns null you can see in the buttom left corner of Mist broser, that mining has startet. It takes a while till the hashrate incrases. You can check the current hashrate with miner.getHashrate()
The null
is expected. If you are mining you will see lots of messages in your console like this:
INFO [07-25|18:46:25] Successfully sealed new block number=72 hash=d0316e…36554e
INFO [07-25|18:46:25] 🔗 block reached canonical chain number=67 hash=a89be4…5a73be
INFO [07-25|18:46:25] 🔨 mined potential block number=72 hash=d0316e…36554e
INFO [07-25|18:46:25] Commit new mining work number=73 txs=0 uncles=0 elapsed=158.932µs
Try the following:
eth.hashrate
will show you whether you are mining (make sure the number is a non-zero number).
If you are not mining, try explicitly starting the miner with one thread e.g. miner.start(1)
Though I wonder... are you mining on a private network / testnet?
Some times the genesis.json with chainId:0 will create this issue, For me below genesis.json helped to solve the issue.
{
"config": {
"chainId": 45,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x75bcb134477f42f6fefbf177f9a610c0665e23a6",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8ffffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
Try with a fresh datadir, init this json, create account, configure with miner ( setEtherBase ), then start miner
miner.start(1) gave null for me. Also eth.hashrate is also 0. But mining works perfectly...!!!
It sometimes so happens that the geth you have attached shows NULL but the other geth console will be showing up the mining trace.
Once you start mining check the other console for which the geth console is attached to, also wait for few minutes and then check for balance.
This happened in my case.