Back to homepage

How to run an Ethereum blockchain locally for development

Published

Quick guide with different options to run an Ethereum blockchain locally that you can use to test, deploy smart contracts and make transactions.


So far I've learned about two different options to run an Ethereum blockchain locally to deploy and test smart contracts: Ganache and Hardhat. Let's see how they work.

Run Ethereum locally with Hardhat

Hardhat is an Ethereum development environment built with Node so it requires both Node.js and NPM.

With Hardhat we just need to run npx hardhat node and it will automatically start a node locally on port 8545. It will also create 20 accounts with 10000ETH each so you can deploy and test your smart contracts.

 npx hardhat node                                                                            ✔
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/

Accounts
========
Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Account #1: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d

Account #2: 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc (10000 ETH)
Private Key: 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a

// more accounts...

With NPX we don't need to actually install hardhat but it requires that you're connected to internet. If you're going to work offline, install hardhat globally with npm i -g hardhat and start your node with hardhat node

Run Ethereum locally with Ganache

If you're using MacOS and your prefer a graphical UI over the terminal, you can use Ganache. It's similar to Hardhat but you'll have a UI to check all the wallet's balances, keys, transactions etc... With Ganache you even get a block explorer!

First you need to download Ganache from its website and install it. After that, just open the app and click on "Quickstart" (make sure Ethereum is selected as the network type).

Ganache dashboard

Similar to Hardhat, Ganache will automatically create 20 accounts with 100ETH so you can use them to deploy your smart contracts or make transactions.

One cool feature is that with Ganache you can save the status of the node so if you've deployed some smart contracts or done transactions and you want to continue working on that project later, you can save it as a workspace.

Import local node and accounts in Metamask

Once your node is running, you can import it on Metamask by going to Settings > Networks > Add Network

Settings import hardhat node in Metamask

You can also import any of the created accounts in Metamask using the private keys provided by both Hardhat or Ganache.

TAGS


If you enjoyed this article consider sharing it on social media or buying me a coffee ✌️

Buy Me A Coffee