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 :
- Is there a way i can find out if blockchain is synced fully?
console.log(blockHeader)shows nothing, why? is it because blockchain is not synced fully ?console.log(pendingTransaction)also not works, why? is it because of the same reason, blockchain not synced fully?