A Technical Guide to Set Up an Ethereum Private Testnet

A Technical Guide to Set Up an Ethereum Private Testnet

Posted by : abhishek.sagu | 28-Dec-2019

  • set up ethereum private testnet

    Ethereum is a public, decentralized blockchain that also acts as an open-source platform to develop decentralized applications. It is one of the most popular blockchains in existence, second only to Bitcoin (BTC) with a market share of USD 19,556,818,393. Setting up an Ethereum testnet can be a daunting task and resource exhaustive. However, we can set up our own Ethereum private testnet without a genesis file, which is easy to do and also less resource-intensive.

    Also, to know more about app development with Ethereum, visit our Ethereum blockchain development services.

    Then, we can test our DApps on this Ethereum private testnet without having to use real ETH.

    Pre Requisites

    OS:- Ubuntu 16.04 or later

    Memory:– C++ compilers are memory-hungry. It is recommended to have at least 1.5 GB of memory available.

    Setting up Ethereum Private Testnet

    By following the below steps, you can set up a private testnet node on your local machine.

    1. Installing geth 

     

    $ sudo add-apt-repository ppa:ethereum/ethereum
    
    $ sudo apt-get update
    
    1. Initiating the blockchain

     

    $  geth --datadir <path to your dataDir here> --dev
    

    Exit the console

    1. Starting the private blockchain

     

    $ geth --dev --port 3000 --networkid 58343 --nodiscover --datadir=<path to data Directory> --maxpeers=0 --rpc --rpcport 8543 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner" --ws --wsport 8546 --wsaddr 127.0.0.1 --allow-insecure-unlock 
    

    Significance of different flags used

    1. –dev:- It means the eth node runs in development mode and there will be mining only when there will be transactions on the given node.
    2. –data-dir:- The path to the datadirectory to be used.
    3. –max peers:- It is 0 since we want to set up private testnet. Noone from outside our machine will be able to connect to the node.
    4. –rpc:- It allows us to use RPC methods.
    5. –rpcport:- Port to be used to connect to our node with RPC requests.
    6. –rpcaddr:-Address of the machine trying to connect to this instance of the node. Since we are setting it up on a local machine, it will be 127.0.0.1.
    7. –rpcapi:-You can mention modules that you can use for RPC requests to the node.
    8. –ws:-It allows our node to be connected with a WebSocket.
    9. –wsport:-Port to be used to connect to our node using web sockets.
    10. –wsddr:- Address of the machine trying to connect to our node through a web socket. Here it is 127.0.0.1
    11. –alow-insecure-unlock:-It allows account creation request to be fulfilled by our node by an HTTP connection.
    1. Attach process and start geth console in a new tab

     

    $ geth attach http://127.0.0.1:8543
    
    1. Create a new account

     

    >  personal.newAccount(password)
    

    Remember this password. The address generated by the above command will be the coinbase address where all the fake ETH for testing will be deposited.

    1.  Check if there is any mining using

     

     > eth.mining
    

    You might not see mining as the private testnet is running in the development mode which means there will be mining only when there is a transaction on the private testnet.

    1. Check the balance of coinbase address

     

     > web3.fromWei(eth.getBalance(eth.coinbase),"ether")

    CONCLUSION

    By following the above steps, you can set up an Ethereum private testnet without a genesis file. It should be done in the development mode so that there is mining only when there is a transaction on a given private testnet. This saves a user’s resources as if you don’t use the development mode, many blocks will be mined very quickly because of low mining difficulty initially.


Leave a Comment

Name is required

Comment is required

Recaptcha is required.

No Comments Yet.

About Author

abhishek.sagu (Writer)

More From Oodles

Request For Proposal

Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.

We would love to hear from you!

Oodles | Blockchain Development Company

Please enter a valid Phone Number

Please remove URL from text

Recaptcha is required.