Smart Contract Tour
This is a tour through some of go-ethereum
’s source code relating to smart contracts:
Setup
The geth
client must be run as a full node for this walkthrough. Full nodes can:
- Mine real ether
- Transfer funds between addresses
- Create contracts and send transactions
- Explore block history
The command line to set up for this tour is:
$ geth --syncmode full --cache 64 --maxpeers 12 \ --rpcapi --wsapi --rinkeby
Typical output looks like:
INFO [06-27|13:38:05] Maximum peer count ETH=12 LES=0 total=12 INFO [06-27|13:38:05] Starting peer-to-peer node instance=Geth/v1.8.11-stable-dea1ce05/linux-amd64/go1.10 INFO [06-27|13:38:05] Allocated cache and file handles database=/home/mslinn/.ethereum/rinkeby/geth/chaindata cache=48 handles=512 INFO [06-27|13:38:05] Writing custom genesis block INFO [06-27|13:38:05] Persisted trie from memory database nodes=355 size=51.91kB time=2.318ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [06-27|13:38:05] Initialised chain configuration config="{ChainID: 4 Homestead: 1 DAO: <nil> DAOSupport: true EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 1035301 Constantinople: <nil> Engine: clique}" INFO [06-27|13:38:05] Initialising Ethereum protocol versions="[63 62]" network=4 INFO [06-27|13:38:05] Loaded most recent local header number=0 hash=6341fd…67e177 td=1 INFO [06-27|13:38:05] Loaded most recent local full block number=0 hash=6341fd…67e177 td=1 INFO [06-27|13:38:05] Loaded most recent local fast block number=0 hash=6341fd…67e177 td=1 INFO [06-27|13:38:05] Regenerated local transaction journal transactions=0 accounts=0 INFO [06-27|13:38:05] Starting P2P networking INFO [06-27|13:38:08] UDP listener up self=enode://fe9c3c8f29c364be0fc7659e1b6f8e9eb90c8ed7861d0b02474d3b46adff1581cc6f4be61a8769da087449358c24a2642cebd3a6797ce49bdeeca087ceea836c@[::]:30303 INFO [06-27|13:38:08] RLPx listener up self=enode://fe9c3c8f29c364be0fc7659e1b6f8e9eb90c8ed7861d0b02474d3b46adff1581cc6f4be61a8769da087449358c24a2642cebd3a6797ce49bdeeca087ceea836c@[::]:30303 INFO [06-27|13:38:08] IPC endpoint opened url=/home/mslinn/.ethereum/rinkeby/geth.ipc INFO [06-27|13:38:18] Block synchronisation started INFO [06-27|13:38:20] Imported new chain segment blocks=54 txs=0 mgas=0.000 elapsed=14.861ms mgasps=0.000 number=54 hash=dafe6e…02bf13 cache=0.00B
Many messages similar to the last one should continuously appear. It typically takes hours for an Ethereum node to fully synchronize with the blockchain.
Start a JavaScript console in another terminal console that connects to the above running
geth
instance with this incantation:$ geth attach ~/.ethereum/rinkeby/geth.ipc
When you are done with this tour, press CTRL-C from the first terminal console to terminate
geth
. Output generated bygeth
as it shuts down will look something like:INFO [06-27|13:39:03] IPC endpoint closed endpoint=/home/mslinn/.ethereum/rinkeby/geth.ipc INFO [06-27|13:39:03] Writing cached state to disk block=46376 hash=7efacc…f41d6c root=d4e03e…041271 INFO [06-27|13:39:03] Persisted trie from memory database nodes=283 size=49.29kB time=9.335ms gcnodes=1617 gcsize=407.84kB gctime=77.473ms livenodes=1 livesize=0.00B INFO [06-27|13:39:03] Writing cached state to disk block=46375 hash=83aa1c…be0d26 root=d4e03e…041271 INFO [06-27|13:39:03] Persisted trie from memory database nodes=0 size=0.00B time=24µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [06-27|13:39:03] Writing cached state to disk block=46249 hash=b4cdf5…f24d50 root=d4e03e…041271 INFO [06-27|13:39:03] Persisted trie from memory database nodes=0 size=0.00B time=9µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [06-27|13:39:03] Blockchain manager stopped INFO [06-27|13:39:03] Stopping Ethereum protocol WARN [06-27|13:39:03] Synchronisation failed, retrying err="header processing canceled (requested)" INFO [06-27|13:39:03] Ethereum protocol stopped INFO [06-27|13:39:03] Transaction pool stopped INFO [06-27|13:39:03] Database closed database=/home/mslinn/.ethereum/rinkeby/geth/chaindata