How to run a light node with Geth
You may be interested in running an Ethereum node. One of the easiest ways to do so is by downloading, installing, and running Geth. With Geth, we can have a light node up and running in minutes.
A light client requires less than 400MB of storage whilst still allowing full interactivity with the Ethereum state. Light clients retrieve data from remote peers, so some queries may take longer to respond in comparison to other sync modes.
For an explanation of the differences between the different sync modes, read our nodes and clients developer docs.
First, install Geth.
After installing Geth, you can run an Ethereum node in "light" mode by running the following command in a Terminal window:
geth --syncmode light
Once launched, Geth will begin connecting to other nodes on Ethereum - known as "peers". The process of connecting to peers may take a while.
When your Geth node has enough peers, it will import headers from new blocks on the chain.
When new block headers no longer have an "age", Geth will be synced to the chain's head.
You can stop your node at any time by pressing CTRL+C.
When restarting the node, Geth will take a few minutes to download block headers created since the node was last run.
Enabling the HTTP-RPC server lets you connect your Ethereum node to other software like wallets, browser extensions, or custom software libraries.
You can enable the HTTP-RPC server by running the following command when launching Geth:
geth --syncmode light --http
Once enabled, run
curl http://127.0.0.1:8545. This should report no error.
To allow remote hosts to connect to your node, launch Geth with the following command:
1geth --syncmode light --http --http.addr 0.0.0.02
Note: this assumes that there is no process blocking requests to your localhost, such as a firewall.
This console allows direct interaction with Ethereum. For example, running the
eth.blockNumber command will print the latest known block number.
Geth runs your node on Ethereum Mainnet by default.
It is also possible to use Geth to run a node on one of the public test networks, by running one of the following commands in Terminal:
geth --syncmode light --ropstengeth --syncmode light --rinkebygeth --syncmode light --goerli
The directory which Geth uses to store raw blockchain data depends on your operating system. Upon running Geth, look for a message that looks like this:
INFO [11-18|14:04:47] Allocated cache and file handles database=/Users/bgu/Library/Ethereum/testnet/geth/lightchaindata cache=768 handles=128
The path following
“database=” should tell you where the blockchain data is stored on your machine. If you’re running a full node, this directory will contain all of the data about every block that has ever been committed to the blockchain. Since we’re running a light node, this directory only contains the block headers.
It’s worth emphasizing here that, at the lowest level, this is where the blockchain lives. The full contents of the blockchain and the EVM state are stored on every full node in the Ethereum network, in directories that look very much like the one on your computer.