3

Does anyone know how to set up a private blockchain in ethereum network? is that possible to run a private ethereum node? I have seen forking of public blockchain like EOS into a private blockchain.i wonder is that possible in ethereum also?

1
  • 1
    did any of the below help? Commented Mar 19, 2019 at 4:21

3 Answers 3

1

Yes, it is possible. I have attached twos links on how to setup it up below that go into this in more depth and am providing a high-level summary.

Overall you need to download the code for Ethereum and make geth, explanations for making geth can be found on the Ethereum page.

After that, the main things you need to do is set up your genesis state in your genesis.json which will look like the below JSON object.

{
  "config": {
        "chainId": 0,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

Then initialize your network with the command

geth init path/to/genesis.json

After that you need to create a dedicated bootnood

$ bootnode --genkey=boot.key
$ bootnode --nodekey=boot.key

Then to startup your member nodes you can use

geth --datadir=path/to/custom/data/folder --bootnodes=<bootnode-enode-url-from-above>

And to start your private miners you can use

geth <usual-flags> --mine --minerthreads=1 --etherbase=0x0000000000000000000000000000000000000000

Links to tutorials https://github.com/ethereum/go-ethereum#operating-a-private-network https://hackernoon.com/set-up-a-private-ethereum-blockchain-and-deploy-your-first-solidity-smart-contract-on-the-caa8334c343d

3
  • 1
    So what about the transaction cost. Does it charge the gas fee? Commented Mar 18, 2019 at 5:29
  • 2
    If you want the fee tobe 0 just use --gasprice 0 when starting up geth. The command would look like geth --networkid 29462 --datadir "./data" --gasprice 0 --nodiscover --port 31313 Commented Mar 18, 2019 at 5:37
  • 1
    In addition to that you can set it up how you would like. You can do proof of authority or proof of work. Additionally you can preseed accounts with ether, so you can start your working accounts with a significant amount of ether to help Commented Mar 18, 2019 at 13:18
1

When you start geth node, by default it connects to mainnet. If you want to setup a private network, you should set --networkId to some random number and should not belong to any existing network. You can refer to following tutorial for setting up a private network. https://medium.com/coinmonks/ethereum-setting-up-a-private-blockchain-67bbb96cf4f1

You can also use puppeth, the cli tool released by geth to set up a private network. using puppeth you can select a consensys algorithm on the go. https://arctouch.com/blog/how-to-set-up-ethereum-blockchain/

1
  • note: sometimes --networkid doesn't work. instead you can use --testnet (by default connects to ropsten) or use name of the testnet eg. --kovan, --ropsten etc.
    – atul
    Commented May 13, 2020 at 13:19
0

We have a very nice Tutorial to create a private PoW network using Pantheon Ethereum client based on Docker Compose. We also have Clique private network and IBFT2.0 private network tutorials.

In the Quickstart tutorial you will find the following things explained :

  • Get Pantheon Quickstart Source Code
  • Build Docker Images and Start Services and Network
  • Run the Block Explorer
  • Run JSON-RPC Requests
  • Creating a Transaction Using MetaMask
  • Use Truffle Pet Shop Tutorial with your private network

Basically it requires you either to use the --network=dev option to run Pantheon with the Pantheon predefined development genesis file, or use the --genesis-file option like --genesis-file=/home/me/me_node/customGenesisFile.json to point to your own genesis.

You can use one of the Pantheon predefined genesis file as a template and change the predefined accounts or parameters like chain id.

Here is the PoW development genesis file sample you could customise:

{
  "config": {
    "chainId": 2018,
    "homesteadBlock": 0,
    "daoForkBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "constantinopleFixBlock": 0,
    "ethash": {
      "fixeddifficulty": 100
    }
  },
  "nonce": "0x42",
  "timestamp": "0x0",
  "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
  "gasLimit": "0x1000000",
  "difficulty": "0x10000",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": {
    "fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
      "privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
      "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
      "balance": "0xad78ebc5ac6200000"
    },
    "627306090abaB3A6e1400e9345bC60c78a8BEf57": {
      "privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
      "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
      "balance": "90000000000000000000000"
    },
    "f17f52151EbEF6C7334FAD080c5704D77216b732": {
      "privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
      "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
      "balance": "90000000000000000000000"
    }
  },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

You can refer to Genesis file part of our doc for more details on the values and links to sample genesis.

Note that you can also add predefined contracts in your genesis by adding something like :

{
  ...
  "alloc": {
      "0x0ffd23af8eebc60b3cfdeed6f814988757237314": {
      "balance": "0x100000000000000000000000000000000000000000000000000",
      "code": "0x6080604052600436106043576000357c010000000000000000000000000000000000000000000000000000000090048063010fc84214604857806355241077146070575b600080fd5b348015605357600080fd5b50605a60a7565b6040518082815260200191505060405180910390f35b348015607b57600080fd5b5060a560048036036020811015609057600080fd5b810190808035906020019092919050505060ad565b005b60005481565b80600081905550807f04474795f5b996ff80cb47c148d4c5ccdbe09ef27551820caa9c2f8ed149cce360405160405180910390a25056fea165627a7a7230582038cb7ea327af8f73feabcfbff64498f1e74831e67f7c75286760d3845c6747c70029",
      "storage": {
        "7aa07e0c924147697605046b7c2c32645b7bbfb41e0ac5d0a84ac93cbb759798": "0000000000000000000000000000000000000000000000000000000000000001",
        "cea2b0602db61f92b76ec4402875cc38eedc9fc425cb1b697fc2265d50fc20fb": "0000000000000000000000000000000000000000000000000000000000000001",
      }
    }
  },
  ...
}

Also note that you don't have to run multiple nodes to just have a test private network. Only one node is enough if it's mining: Enable mining with pantheon --miner-enabled --miner-coinbase <account> where is the address of the account you want the mining rewards to be sent.

Don't hesitate to ask us directly on Gitter (link in the doc footer) for Pantheon specific questions that doesn't really fit on Ethereum SE.

EDIT: Disclaimer, I'm developer at Pegasys so yes it points to our product, sorry, not advertising, just trying to answer to the question with what we have. At least you know ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.