0

I am running geth with this command :

geth --fast --cache=512 --ws --wsorigins="*" --rpc --rpccorsdomain="*" --wsapi "db,eth.subscribe,net,ssh,miner,web3,personal,admin" --datadir /media/username/2TB_HDD/

and i have used web3js and created a nodejs app :

const express = require("express");
const app = express();
const net = require('net');
const Web3 = require("web3");
// const web3 = new Web3("ws://127.0.0.1:8546");
var web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8546"));

web3.eth.getBlock('latest')
.then(console.log);

var subscription = web3.eth.subscribe('newBlockHeaders', function(error, result){
    if (!error)
        console.log(error);
})
.on("data", function(blockHeader){
    console.log(blockHeader);
});

var subscription2 = web3.eth.subscribe('syncing', function(error, sync){
    if (!error)
        console.log(sync);
})
.on("data", function(sync){
    console.log(sync);
})
.on("changed", function(isSyncing){
    if(isSyncing) {
        console.log("stop app operation");
    } else {
        console.log("regain app operation");
    }
});

var subscription3 = web3.eth.subscribe('pendingTransactions', function(error, result){
    if (!error)
        console.log(result);
})
.on("data", function(transaction){
    console.log(transaction);
});

app.listen(3000);

In the console i am getting latest block number : 0. Here is output of eth.syncing :

> eth.syncing
{
  currentBlock: 5046326,
  highestBlock: 5046445,
  knownStates: 407842,
  pulledStates: 401021,
  startingBlock: 5046087
}

I think geth is synced fully? because the latest block number will always keeps increasing, I have these questions, please answer them :

  1. Is there a way i can find out if blockchain is synced fully?
  2. console.log(blockHeader) shows nothing, why? is it because blockchain is not synced fully ?
  3. console.log(pendingTransaction) also not works, why? is it because of the same reason, blockchain not synced fully?
5
  • 1
    Your instance of geth is not fully synced, and it will not return meaningful values until it has finished. – Ismael Feb 7 '18 at 21:00
  • Thanks, do you know how long will it take to sync it fully? with eth.syncing the current and highest block number keeps increasing so how can we know ? – Farhan Feb 8 '18 at 5:05
  • I didn't sync recently but it should take less than a day in fast mode. Currently with geth v1.7.3 you need a SSD with 50 Gb and at least 4 Gb of RAM but I'd recommend 8 Gb at least. Next version will have some improvements to sync with a HDD, currently after a couple of weeks it hasn't finished and I give up. – Ismael Feb 8 '18 at 5:13
  • Thanks, i tried with 60gb ssd 8gb ram but it was full then i used 2TB HDD but it was not ssd so it is still syncing since 2 days, 1st day it downloaded 60gb then 2nd day it is still syncing, now i can only see "imported new state entries" and 11108223 are processed. Should i wait for a week or use new ssd hard disk ? – Farhan Feb 8 '18 at 8:12
  • My last try was 6-8 month ago after waiting two weeks I've switched to a 250Gb SSD and synced in less than a day (final space used was around 50 Gbytes). If you can switch to SSD I'd recommend that it is not worth waiting two weeks, if you cannot switch I'd recommend to try parity (latest release have some improvements for HDD), or the beta version of geth v1.8. – Ismael Feb 8 '18 at 17:28