MallCloud / contracts-api

API for communicating with Ethereum Contracts
0 stars 0 forks source link

docker based ethereum private node creation and setup #9

Closed kgupta15 closed 6 years ago

kgupta15 commented 6 years ago

I require a setup in which ethereum nodes can be created and used in order to deploy smart-contracts. These nodes will then be connected to the core c-api in order to perform Marketplace functions.

The way I understand it (I might be wrong) is that 2 nodes are needed. One is used to deploy contracts with and the other is the one on which contracts are deployed. The one on which contracts are deployed is the one that has to be connected to c-api (api in dockerfile).

All Information I have and stuff I've tried is listed below.

  1. https://github.com/Capgemini-AIE/ethereum-docker
  2. https://blockgeeks.com/two-node-setup-of-a-private-ethereum/
  3. https://blockgeeks.com/two-node-setup-of-a-private-ethereum-on-aws-with-contract-deployment-part-2/
  4. https://github.com/gnidan/docker-eth-dev

I have tried integrating the first repo's method(which uses geth) in order to add docker eth nodes. It works but I can't understand how to deploy smart-contracts. The 2-3 links are info to perform the deployment of contracts. The fourth one performs the deployment successfully but uses testrpc (alternative to geth). I want to use geth in order to do the same thing. Also, I would like to have netstats capability provided in the first repo(but not the last one; yet).

Using truffle for deployment of contracts (as done in 4) will be easiest and fastest to do.

The local setup of mine uses following commands for deployment (to a remote public test-network (commands will differ for private node somewhat)):

  1. Created a .rinkeby folder.
  2. Downloaded genesis json for rinkeby from here
  3. Ran this command :
    geth --datadir=$HOME/.rinkeby --light init rinkeby.json
  4. Ran this command :
    geth --networkid=4 --datadir=$HOME/.rinkeby --syncmode=light --bootnodes=enode://a24ac7c5484ef4ed0c5eb2d36620ba4e4aa13b8c84684e1b4aab0cebea2ae45cb4d375b77eab56516d34bfbd3c1a833fc51296ff084b770b94fb9028c4d25ccf@52.169.42.101:30303?discport=30304 --rpc --rpcapi db,eth,net,web3,personal --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*"
  5. After I had geth connected to the network, I used truffle with the following code & command to deploy the contract:

Code:

module.exports = {
  networks: {
    rinkeby: {
      network_id: 4,
      host: '127.0.0.1',
      port: 8545,
      gas: 4000000,
      from: <your account address>
    },
  },
  rpc: {
    // Use the default host and port when not using rinkeby
    host: 'localhost',
    port: 8080,
  },
};

Command:

truffle compile; truffle migrate --network rinkeby

As you can see here, for rinkeby, a genesis.json is required. A genesis.json defines the block system for network and is available in both 1 and 4 repos. After that, the geth based commands are quite similar.