Software Development

First steps with Ethereum Private Networks and Smart Contracts on Ubuntu 16.04

Ethereum is still in that “move fast and break things” phase. The docs for contracts[1] are very out of date, even the docs for mining have some out of date content in[2].

I wanted a very simple guide to setting up a small private network for testing smart contracts. I couldn’t find a simple one that worked. After much trial and error and digging around on Stackexchange, see below the steps I eventually settled on to get things working with a minimum of copy/paste. Hope it will prove useful for other noobs out there and that more experienced people might help clear things up that I have misunderstood.

I’ll do 3 things:

  1. Set up my first node and do some mining on it
  2. Add a very simple contract
  3. Add a second node to the network

First make sure you have installed ethereum (geth) and solc, for example with:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum solc

Set up first node and do some mining on it

Create a genesis file – the below is about as simple as I could find. Save it as genesis.json in your working directory.

{
  "config": {
    "chainId": 1907,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "difficulty": "10",
  "gasLimit": "2100000",
  "alloc": {}
}

Make a new data directory for the first node and set up two accounts to be used by that node. (Obviously your addresses will differ to the examples you see below).

ethuser@host01:~$ mkdir node1
ethuser@host01:~$ geth --datadir node1 account new
WARN [07-19|14:16:22] No etherbase set and no accounts found as default 
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {f74afb1facd5eb2dd69feb589213c12be9b38177}
ethuser@host01:~$ geth --datadir node1 account new
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {f0a3cf66cc2806a1e9626e11e5324360ee97f968}

Choose a networkid for your private network and initiate the first node:

ethuser@host01:~$ geth --datadir node1 init genesis.json
INFO [07-19|14:21:44] Allocated cache and file handles         database=/home/ethuser/node1/geth/chaindata cache=16 handles=16
....
INFO [07-19|14:21:44] Successfully wrote genesis state         database=lightchaindata                          hash=dd3f8d…707d0d

Now launch a geth console

ethuser@host01:~$ geth --datadir node1 --networkid 98765 console
INFO [07-19|14:22:42] Starting peer-to-peer node               instance=Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1
...
 datadir: /home/ethuser/node1
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> 

The first account you created is set as eth.coinbase. This will earn ether through mining. It does not have any ether yet[3], so we need to mine some blocks:

> eth.coinbase
"0xf74afb1facd5eb2dd69feb589213c12be9b38177"
> eth.getBalance(eth.coinbase)
0
> miner.start(1)

First time you run this it will create the DAG. This will take some time. Once the DAG is completed, leave the miner running for a while until it mines a few blocks. When you are ready to stop it, stop it with miner.stop().

.....
INFO [07-19|14:40:03] 🔨 mined potential block                  number=13 hash=188f37…47ef07
INFO [07-19|14:40:03] Commit new mining work                   number=14 txs=0 uncles=0 elapsed=196.079µs
> miner.stop()
> eth.getBalance(eth.coinbase)
65000000000000000000
> eth.getBalance(eth.accounts[0])
65000000000000000000

The first account in the account list is the one that has been earning the ether for its mining, so all we prove above is that eth.coinbase == eth.accounts[0]. Now we’ve got some ether in the first account, let’s send it to the 2nd account we created. The source account has to be unlocked before it can send a transaction.

> eth.getBalance(eth.accounts[1])
0
> personal.unlockAccount(eth.accounts[0])
Unlock account 0xf74afb1facd5eb2dd69feb589213c12be9b38177
Passphrase: 
true
> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(3,"ether")})
INFO [07-19|14:49:12] Submitted transaction                    fullhash=0xa69d3fdf5672d2a33b18af0a16e0b56da3cbff5197898ad8c37ced9d5506d8a8 recipient=0xf0a3cf66cc2806a1e9626e11e5324360ee97f968
"0xa69d3fdf5672d2a33b18af0a16e0b56da3cbff5197898ad8c37ced9d5506d8a8"

For this transaction to register it has to be mined into a block, so let’s mine one more block:

> miner.start(1)
INFO [07-19|14:50:14] Updated mining threads                   threads=1
INFO [07-19|14:50:14] Transaction pool price threshold updated price=18000000000
null
> INFO [07-19|14:50:14] Starting mining operation 
INFO [07-19|14:50:14] Commit new mining work                   number=14 txs=1 uncles=0 elapsed=507.975µs
INFO [07-19|14:51:39] Successfully sealed new block            number=14 hash=f77345…f484c9
INFO [07-19|14:51:39] 🔗 block reached canonical chain          number=9  hash=2e7186…5fbd96
INFO [07-19|14:51:39] 🔨 mined potential block                  number=14 hash=f77345…f484c9

> miner.stop()
true
> eth.getBalance(eth.accounts[1])
3000000000000000000

One small point: the docs talk about miner.hashrate. This no longer exists, you have to use eth.hashrate if you want to see mining speed.

Add a very simple contract

The example contract is based on an example in the Solidity docs. There is no straightforward way to compile a contract into geth. Browser-solidity is a good online resource but I want to stick to the local server as much as possible for this posting. Save the following contract into a text file called simple.sol

pragma solidity ^0.4.13;

contract Simple {
  function arithmetics(uint _a, uint _b) returns (uint o_sum, uint o_product) {
    o_sum = _a + _b;
    o_product = _a * _b;
  }

  function multiply(uint _a, uint _b) returns (uint) {
    return _a * _b;
  }
}

And compile it as below:

ethuser@host01:~/contract$ solc -o . --bin --abi simple.sol
ethuser@host01:~/contract$ ls
Simple.abi  Simple.bin  simple.sol

The .abi file holds the contract interface and the .bin file holds the compiled code. There is apparently no neat way to load these files into geth so we will need to edit those files into scripts that can be loaded. Edit the files so they look like the below:

ethuser@host01:~/contract$ cat Simple.abi
var simpleContract = eth.contract([{"constant":false,"inputs":[{"name":"_a","type":"uint256"},{"name":"_b","type":"uint256"}],"name":"multiply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_a","type":"uint256"},{"name":"_b","type":"uint256"}],"name":"arithmetics","outputs":[{"name":"o_sum","type":"uint256"},{"name":"o_product","type":"uint256"}],"payable":false,"type":"function"}])

and

ethuser@host01:~/contract$ cat Simple.bin
personal.unlockAccount(eth.accounts[0])

var simple = simpleContract.new(
{ from: eth.accounts[0],
data: "0x6060604052341561000f57600080fd5b5b6101178061001f6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063165c4a161460475780638c12d8f0146084575b600080fd5b3415605157600080fd5b606e600480803590602001909190803590602001909190505060c8565b6040518082815260200191505060405180910390f35b3415608e57600080fd5b60ab600480803590602001909190803590602001909190505060d6565b604051808381526020018281526020019250505060405180910390f35b600081830290505b92915050565b600080828401915082840290505b92509290505600a165627a7a72305820389009d0e8aec0e9007e8551ca12061194d624aaaf623e9e7e981da7e69b2e090029",
gas: 500000
}
)

Two things in particular to notice:

  1. In the .bin file you need to ensure that the from account is unlocked
  2. The code needs to be enclosed in quotes and begin with 0x

Launch geth as before, load the contract scripts, mine them into a block and then interact with the contract. We won’t be able to do anything useful with the contract until it’s mined, as you can see below.

ethuser@host01:~$ geth --datadir node1 --networkid 98765 console
INFO [07-19|16:33:02] Starting peer-to-peer node instance=Geth/v1.6.7-stable-ab5646c5/linux-amd64/go1.8.1
....
> loadScript("contract/Simple.abi")
true
> loadScript("contract/Simple.bin")
Unlock account 0xf74afb1facd5eb2dd69feb589213c12be9b38177
Passphrase: 
INFO [07-19|16:34:16] Submitted contract creation              fullhash=0x318caec477b1b5af4e36b277fe9a9b054d86744f2ee12e22c12a7d5e16f9a022 contract=0x2994da3a52a6744aafb5be2adb4ab3246a0517b2
true
> simple
{
....
  }],
  address: undefined,
  transactionHash: "0x318caec477b1b5af4e36b277fe9a9b054d86744f2ee12e22c12a7d5e16f9a022"
}
> simple.multiply
undefined
> miner.start(1)
INFO [07-19|16:36:07] Updated mining threads                   threads=1
...
INFO [07-19|16:36:21] 🔨 mined potential block                  number=15 hash=ac3991…83b9ac
...
> miner.stop()
true
> simple.multiply
function()
> simple.multiply.call(5,6)
30
> simple.arithmetics.call(8,9)
[17, 72]

Set up a second node in the network

I’ll run the second node on the same virtual machine to keep things simple. The steps to take are:

  1. Make sure the existing geth node is running
  2. Create an empty data directory for the second node
  3. Add accounts for the second geth node as before
  4. Initialise the second geth node using the same genesis block as before
  5. Launch the second geth node setting bootnodes to point to the existing node

The second geth node will need to run on a non-default port.

Find the enode details from the existing geth node:

> admin.nodeInfo
{  enode: "enode://08993401988acce4cd85ef46a8af10d1cacad39652c98a9df4d5785248d1910e51d7f3d330f0a96053001264700c7e94c4ac39d30ed5a5f79758774208adaa1f@[::]:30303", 
...

We will need to substitute [::] with the IP address of the host, in this case 127.0.0.1

To set up the second node:

ethuser@host01:~$ mkdir node2
ethuser@host01:~$ geth --datadir node2 account new
WARN [07-19|16:55:52] No etherbase set and no accounts found as default 
Your new account is locked with a password. Please give a password. Do not forget this password.
Passphrase: 
Repeat passphrase: 
Address: {00163ea9bd7c371f92ecc3020cfdc69a32f70250}
ethuser@host01:~$ geth --datadir node2 init genesis.json
INFO [07-19|16:56:14] Allocated cache and file handles         database=/home/ethuser/node2/geth/chaindata cache=16 handles=16
...
INFO [07-19|16:56:14] Writing custom genesis block 
INFO [07-19|16:56:14] Successfully wrote genesis state         database=lightchaindata                          hash=dd3f8d…707d0d
ethuser@host01:~$ geth --datadir node2 --networkid 98765 --port 30304 --bootnodes "enode://08993401988acce4cd85ef46a8af10d1cacad39652c98a9df4d5785248d1910e51d7f3d330f0a96053001264700c7e94c4ac39d30ed5a5f79758774208adaa1f@127.0.0.1:30303" console

Wait a little and you will see block synchronisation taking place

> INFO [07-19|16:59:36] Block synchronisation started 
INFO [07-19|16:59:36] Imported new state entries               count=1 flushed=0 elapsed=118.503µs processed=1 pending=4 retry=0 duplicate=0 unexpected=0
INFO [07-19|16:59:36] Imported new state entries               count=3 flushed=2 elapsed=339.353µs processed=4 pending=3 retry=0 duplicate=0 unexpected=0

To check that things have fully synced, run eth.getBlock('latest') on each of the nodes. If things aren’t looking right then use admin.peers on each node to make sure that each node has peered with the other node.

Now you can run the miner on one node and run transactions on the other node.

Notes

[1]  https://github.com/ethereum/go-ethereum/issues/3793:

Compiling via RPC has been removed in #3740 (see ethereum/EIPs#209 for why). We will bring it back under a different method name if there is sufficient user demand. You’re the second person to complain about it within 2 days, so it looks like there is demand.

[2] The official guide to Contracts is out of date. I spotted some out of date material on Mining and submitted an issue but updating the official docs doesn’t seem much of a priority so I figured I would collect my learnings here for now.
[3] You can pre-allocate ether in the genesis.json if you prefer, but that would mean a little more cut and paste which I am doing my best to minimise here.

 

Edited 26 Aug 2017

No need to specify networkid when initialising the node.

Edited 25 Jan 2018

Decreased difficulty to 10 per this comment from bglmmz, thanks for the suggestion.

79 thoughts on “First steps with Ethereum Private Networks and Smart Contracts on Ubuntu 16.04

  1. Thanks a lot!

    Finally an example that works… even the examples in the official documentation are out of date!

    Incredibly useful, really appreciate it! 🙂

    1. Glad you found it useful, JaVinci, and thanks for taking the time to leave a comment. I agree, I can’t believe how bad the official docs are at keeping up to date.

    1. Hey Gerald, glad you found this useful. Setting up with two physical nodes follows the same principles. If you are only running one geth on each physical node then you can run your 2nd geth on IP2 on the default port (30303). You will just need to:

      1. Make sure that you copy the genesis.json file to the 2nd machine so you initialise both nodes with the same genesis block

      2. Specify the correct IP address when launching your 2nd geth node on IP2, e.g: geth --datadir node2 --networkid 98765 --bootnodes "enode://08993401988acce4cd85ef46a8af10d1cacad39652c98a9df4d5785248d1910e51d7f3d330f0a96053001264700c7e94c4ac39d30ed5a5f79758774208adaa1f@IP2ADDRESS:30303" console

      Good luck

      1. Thanks Alan, my first chain with 20 blocks is OK
        I use VirtualBox and check that each VM produces ~10 blocks

        As old IT professor, I try to understand all fields of block

        My questions (before I decide to study code) :

        1) Why answer from geth dump blocknumber is very different from Block explorer like https://etherscan.io/block/4222840 ?

        2) which tool gives the detail of block & transaction defined in yellow paper ?

    1. Hi Basant – a useful trick I’ve found to debug these sorts of issues is to run the following:

      debug.verbosity(4);miner.start(1);admin.sleepBlocks(3);miner‌​.stop();debug.verbos‌​ity(3);

      This will increase the log level, start the miner, wait for 3 blocks to be mined, then stop the miner and lower the log level to a normal level. Hopefully this will help you understand why the miner is not starting.

  2. Hi Alan,
    Out of Curiosity i landed up on you blog(after your comment on https://ethereum.stackexchange.com/questions/25153/ethereum-pending-transaction/25196?noredirect=1#comment26620_25196 )

    I went through the above post and tried implementing it from scratch.
    i executed the geth init command . balance is rightly zero.

    but then when i run miner.start() (for the first time ) NO DAG is created
    I get the following-

    INFO [08-30|19:36:26] IPC endpoint opened: /home/vishal/Ethereum/Impl/AB_Tut/node1/geth.ipc
    INFO [08-30|19:36:26] Mapped network port proto=tcp extport=30303 intport=30303 interface=”UPNP IGDv1-IP1″
    INFO [08-30|19:37:00] Updated mining threads threads=1
    INFO [08-30|19:37:00] Transaction pool price threshold updated price=18000000000
    INFO [08-30|19:37:00] Starting mining operation
    INFO [08-30|19:37:00] Commit new mining work number=1 txs=0 uncles=0 elapsed=441.46µs

    1. The DAG gets created in your home directory (have a look in .ethash directory in your home directory), so if you are using the same user account then you probably already have a DAG created so no need to create a new one. Mining is very memory intensive. I was experimenting the other day and a job that took less than 1 min to mine a block on a 2Gb virtual machine would take about 20 or 30 minutes with a 1Gb VM. How much memory does your VM have?

  3. When do in the follwing way the DAG is getting created and everythings fine

    geth –datadir node2 account new

    geth –datadir node2/ –dev –nodiscover –mine –unlock 0 –password ~/Ethereum/Impl/password.sec

    Have no idea why do you have any?

  4. Hi Alan,

    I am trying to follow your tutorial here. When I reach last step of –bootnodes, the command just starts geth-js console. As per your instructions, it should start synchronizing but it doesn’t. Even admin.peers returns empty array. Any idea?

    1. Why bootnode doesn’t work if “—nodiscover” flag is used while creating initial node? I tried the same steps with and without—nodiscover flag. Without everything works fine but with new node doesn’t do any synchronization. Any idea how to fix it?

  5. Hello Alan,
    Thank you very much for such a wonderful article. However I am facing an issue here when I start the miner process with miner.start(1). It gives me error as below. I tried to search for the solution but could not find any. I am using Ubuntu 16.04 LTS on Intel i3 processor, 4 GB RAM and 4 GB Swap.

    > miner.start(1)
    INFO [10-24|18:55:59] Updated mining threads threads=1
    INFO [10-24|18:55:59] Transaction pool price threshold updated price=18000000000
    INFO [10-24|18:55:59] Starting mining operation
    null
    > INFO [10-24|18:55:59] Commit new mining work number=1 txs=1 uncles=0 elapsed=667.378µs
    INFO [10-24|18:56:02] Generating ethash verification cache epoch=1 percentage=80 elapsed=3.010s
    INFO [10-24|18:56:03] Generated ethash verification cache epoch=1 elapsed=3.687s
    ERROR[10-24|18:56:03] Failed to generate mapped ethash dataset epoch=1 err=”cannot allocate memory”
    runtime: out of memory: cannot allocate 2164260864-byte block (119799808 in use)
    fatal error: out of memory

  6. ubunbu 16.04.3.amd64
    geth 1.7.2-stable

    run miner.start(1), and nothing happened.
    ——————————————————
    > miner.start(1);
    INFO [10-31|03:17:10] Updated mining threads threads=1
    INFO [10-31|03:17:10] Transaction pool price threshold updated price=18000000000
    null
    > INFO [10-31|03:17:10] Starting mining operation
    INFO [10-31|03:17:10] Commit new mining work number=1 txs=0 uncles=0 elapsed=833.69µs

  7. Hi
    I coudl not even get past 1st mining. the eth.coinbase balance remains 0 for long time. i left it for mining for about 2 hours and still same issue. y such a slow pace even for a private blockchain that too which was just created

  8. Thanks for this. As of Feb 18, the official documentation is *still* out of date.

    Per some of the comments: mining really is memory intensive. I was running on a Linux VM on top of WIndows, with 4 GB RAM in the VM, Firefox also running. No visible prorgress, even with difficulty 1 in the “genesis.json”. I upped the VM to 10 GM, and bam, the blocks come fast.

    1. Hi Robin, yes you are right it is eye-opening how little attention Ethereum gives to keeping its docs up to date. For example I raised this issue https://github.com/ethereum/go-ethereum/issues/14802 in July 2017, to make a trivial change in one of the wiki pages. It still hasn’t been implemented. (I even checked that this page is still accessible from the main docs).

      Ref the memory yes a lot of people have commented on that too. I did a bit more digging into geth to see how memory affected mining speed and wrote it up here: https://alanbuxton.wordpress.com/2018/01/28/memory-and-mining-in-ethereum-a-look-in-geth-internals/

  9. Following the second node instructions… they didn’t connect. I had to do an admin.addPeer(‘enode://7250e022e00dbd5b4ef9418ddd6bda954848fcc91ba1ba643bfbd837c931d97cb86b70a3140e0b95cd49737153ef391b3b9c9290b387af7286e1361fb385ca0f@127.0.0.1:30303’)
    within the second console; then it quickly started syncing.

  10. Hi Alan,
    Here you have used call function. But what if I want to store the output as a transaction in a block, how do I go about it? (Because sendTransaction doesn’t seem to store the output details)
    Also, how do I access the functions of the deployed contract from another node?

  11. Hello Alan,
    If I restart a network using the same network id, then will a contract that I had deployed earlier still be there? If yes, then how can I store it in a variable to access it’s functions?

  12. i am stuck on the step geth –datadir node1 init genesis.json. this my output and it goes on for hours. what am i doing wrong please?
    :
    maahes@maahes:~/node1$ geth node1 init genesis.json
    INFO [04-26|21:39:11] Maximum peer count ETH=25 LES=0 total=25
    INFO [04-26|21:39:11] Starting peer-to-peer node instance=Geth/v1.8.7-unstable/linux-amd64/go1.10.1
    INFO [04-26|21:39:11] Allocated cache and file handles database=/home/maahes/.ethereum/geth/chaindata cache=768 handles=512
    INFO [04-26|21:39:14] Initialised chain configuration config=”{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: Engine: ethash}”
    INFO [04-26|21:39:14] Disk storage enabled for ethash caches dir=/home/maahes/.ethereum/geth/ethash count=3
    INFO [04-26|21:39:14] Disk storage enabled for ethash DAGs dir=/home/maahes/.ethash count=2
    INFO [04-26|21:39:14] Initialising Ethereum protocol versions=”[63 62]” network=1
    INFO [04-26|21:39:14] Loaded most recent local header number=4145254 hash=86776f…ca6afc td=668658264056747917164
    INFO [04-26|21:39:14] Loaded most recent local full block number=0 hash=d4e567…cb8fa3 td=17179869184
    INFO [04-26|21:39:14] Loaded most recent local fast block number=4112671 hash=9e55e5…f77818 td=615897908561340877217
    INFO [04-26|21:39:14] Loaded local transaction journal transactions=0 dropped=0
    INFO [04-26|21:39:14] Upgrading chain index type=bloombits percentage=39
    INFO [04-26|21:39:14] Regenerated local transaction journal transactions=0 accounts=0
    INFO [04-26|21:39:14] Starting P2P networking
    INFO [04-26|21:39:16] Mapped network port proto=udp extport=30303 intport=30303 interface=”UPNP IGDv1-IP1″
    INFO [04-26|21:39:16] UDP listener up self=enode://3fc5ffbd3c48d3f508a8ff20fbb369763435fb755c8247b378676bbd3b6fa3f1279bacc9e6ff1c909a29c34a178d5e71e3dd8497631652acb45a7f37da2004f2@66.25.185.242:30303
    INFO [04-26|21:39:16] RLPx listener up self=enode://3fc5ffbd3c48d3f508a8ff20fbb369763435fb755c8247b378676bbd3b6fa3f1279bacc9e6ff1c909a29c34a178d5e71e3dd8497631652acb45a7f37da2004f2@66.25.185.242:30303
    INFO [04-26|21:39:16] IPC endpoint opened url=/home/maahes/.ethereum/geth.ipc
    INFO [04-26|21:39:16] Mapped network port proto=tcp extport=30303 intport=30303 interface=”UPNP IGDv1-IP1″
    INFO [04-26|21:39:22] Upgrading chain index type=bloombits percentage=41
    INFO [04-26|21:39:26] Block synchronisation started
    INFO [04-26|21:39:31] Upgrading chain index type=bloombits percentage=43
    INFO [04-26|21:39:32] Imported new block headers count=0 elapsed=8.114ms number=4112863 hash=441fe1…ecaa82 ignored=192
    INFO [04-26|21:39:39] Upgrading chain index type=bloombits percentage=44
    INFO [04-26|21:39:42] Imported new block receipts count=2 elapsed=2.312ms number=4112673 hash=343109…02ffc1 size=101.39kB ignored=0
    INFO [04-26|21:39:42] Imported new block headers count=0 elapsed=11.219ms number=4113055 hash=3fed66…4d2694 ignored=192
    INFO [04-26|21:39:47] Upgrading chain index type=bloombits percentage=46
    INFO [04-26|21:39:52] Imported new block headers count=0 elapsed=123.164ms number=4115103 hash=930cd4…de844a ignored=2048
    INFO [04-26|21:39:52] Imported new block headers count=0 elap

    1. Hi, according to your command you have missed out the --datadir parameter. This means that when you run geth, it comes to an argument it doesn’t understand (node1) and apparently disregards the rest. Therefore it ends up trying to sync with the main Ethereum blockchain. You can see in the output that it’s using network 1.

      To test this you can go to a directory that doesn’t have a genesis.json file in and try the following commands:

      $ geth --datadir node1 init genesis.json
      Fatal: Failed to read genesis file: open genesis.json: no such file or directory
      $ geth node1 init genesis.json
      INFO [04-27|06:19:30] Maximum peer count ETH=25 LES=0 total=25
      INFO [04-27|06:19:30] Starting peer-to-peer node instance=Geth/v1.8.1-stable-1e67410e/linux-amd64/go1.9.4
      ...

      1. you are awesome for this, i’ve made more progress through the list. my biggest concern is learning exactly what i’m typing in instead of just blindly doing it

  13. one more problem, in the final steps setting up the second node, i get this error print out:

    maahes@maahes:~/node2$ geth –datadir /home/maahes/node2 –networkid 98765 –port 30304 –bootnodes
    Incorrect Usage. flag needs an argument: -bootnodes

    flag needs an argument: -bootnodes

    1. I think the code formatting in this blog layout isn’t so clear. The bootnodes appear on the next line because of line spacing issues.

      geth --datadir node2 --networkid 98765 --port 30304 --bootnodes "enode://08993401988acce4cd85ef46a8af10d1cacad39652c98a9df4d5785248d1910e51d7f3d330f0a96053001264700c7e94c4ac39d30ed5a5f79758774208adaa1f@127.0.0.1:30303" console

      But just make sure that you find the correct address based on your existing node in the network.

      1. i have use the same command and my address he correct but the result found was wrong

  14. if i want to make the blockchain public and change everything named ethereum or eth or ether to my own coins name, how do i go about doing that please?

    1. Good question, maahes. That is a bit beyond the scope of this brief introduction. You will need to look for tutorials on ERC-20 tokens or in-depth tutorials on smart contracts. Good luck!

  15. I have added to two nodes inside my private network and they two are connected properly with each other. Now, I have deployed smart contract in one node and want to get that contract inside another contract then how to do that ?

  16. HI,

    Thank you for the great guide!!!
    When I want to add contract my contract, should I mine it by both the nodes? (so it will be in all the nodes’ blockchains )

    How can I see if the contract was added to blockchains?
    Is there a way to start the blockchain again without doing all this configurations (I have done these configurations once, should I ever do it again?)

    Thank you

  17. Hi Alan, Thank you for the great tutorial!
    If you have a bigger contract, should you be mining for a longer time?
    I am currently stuck on the “Adding a very simple contract” portion. After I run miner.stop() and do my contract’s equivalent of simple.multiply, I still get “undefined”, even though I have successfully followed all the steps prior to this one. Do you have any ideas why this might be the case?

    1. You say “my contract’s equivalent of”… does this mean that you are using some different code? If so it would be useful to share, for example as a gist, though I may not be able to help a huge amount as my own knowledge of writing smart contracts is pretty limited.

  18. Hi Alan, it such a great tutorial !!!! I am dollowing it on a Raspberry Pi 3 with 1GB RAM. I am at a dead end. Mining works fine if I use the –dev flag. However if I try the last part of the tutorial, connecting 2 peers together it doesnt happen if I am suing –dev. If I remove the flag they can connect but then I cant mine anything because I get the “Panic out of memory” error. Would you know why this is happening and how to connect to peers using the flag dev? Thanks a lot

  19. Hi, plz help last comment generate different result given below after command.

    geth –datadir node2 –networkid 98765 –port 30304 –bootnodes “enode://08993401988acce4cd85ef46a8af10d1cacad39652c98a9df4d5785248d1910e51d7f3d330f0a96053001264700c7e94c4ac39d30ed5a5f79758774208adaa1f@127.0.0.1:30303″ console

    WARN [10-03|13:01:49.269] Sanitizing cache to Go’s GC limits provided=1024 updated=656
    INFO [10-03|13:01:49.273] Maximum peer count ETH=25 LES=0 total=25
    INFO [10-03|13:01:49.278] Starting peer-to-peer node instance=Geth/v1.8.16-stable-477eb093/linux-amd64/go1.10
    INFO [10-03|13:01:49.279] Allocated cache and file handles database=/home/rubab-zahra/node2/geth/chaindata cache=492 handles=512
    INFO [10-03|13:01:49.485] Initialised chain configuration config=”{ChainID: 1907 Homestead: 0 DAO: DAOSupport: false EIP150: EIP155: 0 EIP158: 0 Byzantium: Constantinople: Engine: unknown}”
    INFO [10-03|13:01:49.485] Disk storage enabled for ethash caches dir=/home/rubab-zahra/node2/geth/ethash count=3
    INFO [10-03|13:01:49.489] Disk storage enabled for ethash DAGs dir=/home/rubab-zahra/.ethash count=2
    INFO [10-03|13:01:49.490] Initialising Ethereum protocol versions=”[63 62]” network=98765
    INFO [10-03|13:01:49.492] Loaded most recent local header number=0 hash=357b5e…1b20b9 td=10 age=49y5mo2w
    INFO [10-03|13:01:49.498] Loaded most recent local full block number=0 hash=357b5e…1b20b9 td=10 age=49y5mo2w
    INFO [10-03|13:01:49.498] Loaded most recent local fast block number=0 hash=357b5e…1b20b9 td=10 age=49y5mo2w
    INFO [10-03|13:01:49.499] Loaded local transaction journal transactions=0 dropped=0
    INFO [10-03|13:01:49.500] Regenerated local transaction journal transactions=0 accounts=0
    INFO [10-03|13:01:49.545] Starting P2P networking
    INFO [10-03|13:01:51.751] UDP listener up self=enode://759db5ac628a9991ab8e3e3a013759445a80cc4f370ee44e7301a6b46ea45b5a3e6ef7348120d2d656c345a68d18d024340afa72fd6b53559d9bc48c09612d9f@[::]:30304
    INFO [10-03|13:01:51.800] RLPx listener up self=enode://759db5ac628a9991ab8e3e3a013759445a80cc4f370ee44e7301a6b46ea45b5a3e6ef7348120d2d656c345a68d18d024340afa72fd6b53559d9bc48c09612d9f@[::]:30304
    INFO [10-03|13:01:51.805] IPC endpoint opened url=/home/rubab-zahra/node2/geth.ipc
    Welcome to the Geth JavaScript console!

    instance: Geth/v1.8.16-stable-477eb093/linux-amd64/go1.10
    INFO [10-03|13:01:52.695] Etherbase automatically configured address=0x9d517BE1938E229bfa3E9B5db5452c5D5c16B978
    coinbase: 0x9d517be1938e229bfa3e9b5db5452c5d5c16b978
    at block: 0 (Thu, 01 Jan 1970 05:00:00 +05)
    datadir: /home/rubab-zahra/node2
    modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

  20. Hi Alan, this is a really great tutorial. I am lucky to found this site.
    I have a question regarding the last step. after I typed in eth.getBlock(‘latest’), block synchronisation started, but the console printed out this

    WARN [10-24|16:48:32.650] Header broke chain ancestry peer=6ac5ab8773c31d83 number=60 hash=56a4cc…2990d3
    WARN [10-24|16:48:32.650] Synchronisation failed, dropping peer peer=6ac5ab8773c31d83 err=”retrieved hash chain is invalid”

    what should I do?
    and about the running contracts and mining, can you give an example on how to do that?

    1. I found out that I have to wait long enough for it to be synchronized, so problem is solved.

      to mine in one account and the other, I found out that I need to open 2 terminal windows. one to control the 2nd node, and one for 1st node. Then it is all the same as your code above.

      1. Do you have any references or tutorial about connecting different computer to the same network?

  21. I am stuck at the math part of this. No matter what values I send to the functions, I always get 0 back. Here’s the solidity code that I’m using (slight modifications to take into account newer version of solidity):

    pragma solidity >= 0.4.13;

    contract Simple {
    function arithmetics(uint256 _a, uint256 _b) public returns (uint256 o_sum, uint256 o_product)
    { o_sum = _a + _b;
    o_product = _a * _b;
    }

    function multiply(uint256 _a, uint256 _b) public returns (uint256) {
    return _a * _b;
    }
    }

    I get no errors, but the return value (or values is/are always 0). From the geth console:

    > miner.stop()
    null
    > simple.multiply
    function()
    > simple.arithmetics
    function()
    > simple
    {
    abi: [{
    constant: false,
    inputs: [{…}, {…}],
    name: “multiply”,
    outputs: [{…}],
    payable: false,
    stateMutability: “nonpayable”,
    type: “function”
    }, {
    constant: false,
    inputs: [{…}, {…}],
    name: “arithmetics”,
    outputs: [{…}, {…}],
    payable: false,
    stateMutability: “nonpayable”,
    type: “function”
    }],
    address: “0x4145ed05813bc2e7075060dbd92ba383e3d451bd”,
    transactionHash: “0x0879d7714022cd1706471ea7c758362bb3515a5ad2bfcb19267221f4dbd6f9e5”,
    allEvents: function(),
    arithmetics: function(),
    multiply: function()
    }

    > simple.multiply.call(10,10)
    0
    > simple.arithmetics.call(10,10)
    [0, 0]

    What am I doing wrong?

    Thank you!

Leave a reply to geth object still unpopulated after mining - Finance Money Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.