├── .gitignore ├── Dockerfile ├── Readme.md ├── coffeeify ├── config ├── genesis.json └── password.txt ├── console.sh ├── kill.sh ├── lib └── geth_mine.coffee ├── package.json ├── prepare_genesis ├── prepare_genesis.coffee ├── run.sh ├── run_localdir.sh └── screenshots └── main.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | datadir 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | # -------------------- 4 | # nodejs 5 | # 6 | RUN apt-get update 7 | RUN apt-get install -y curl rlwrap 8 | 9 | RUN curl https://deb.nodesource.com/node_6.x/pool/main/n/nodejs/nodejs_6.2.0-1nodesource1~trusty1_amd64.deb > node.deb \ 10 | && dpkg -i node.deb \ 11 | && rm node.deb 12 | 13 | RUN npm install -g pangyp\ 14 | && ln -s $(which pangyp) $(dirname $(which pangyp))/node-gyp\ 15 | && npm cache clear\ 16 | && node-gyp configure || echo "" 17 | 18 | ENV NODE_ENV production 19 | # 20 | # / nodejs 21 | # -------------------- 22 | 23 | ENV DEBIAN_FRONTEND noninteractive 24 | 25 | RUN apt-get update && \ 26 | apt-get upgrade -q -y && \ 27 | apt-get dist-upgrade -q -y && \ 28 | apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 923F6CA9 && \ 29 | echo "deb http://ppa.launchpad.net/ethereum/ethereum/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/ethereum.list && \ 30 | apt-get update && \ 31 | apt-get install -q -y geth && \ 32 | apt-get clean && \ 33 | rm -rf /var/lib/apt/lists/* && \ 34 | apt-get update 35 | 36 | RUN apt-get install -y git 37 | RUN npm i -g coffee-script 38 | 39 | WORKDIR /app 40 | 41 | ADD package.json /app 42 | ADD package.json /tmp/package.json 43 | RUN npm i 44 | 45 | ADD config /app/config 46 | # RUN ls (add/change this line if you want to regenerate a naw address) 47 | 48 | RUN geth --datadir . --password config/password.txt account new 49 | # RUN geth account list (for verification) 50 | 51 | ADD coffeeify /app 52 | ADD prepare_genesis /app 53 | 54 | ADD *.coffee /app 55 | ADD lib /app 56 | RUN ./coffeeify 57 | 58 | RUN ./prepare_genesis 59 | RUN geth --datadir . --dev init config/genesis.json 60 | RUN cat ./config/genesis.json 61 | 62 | # this line will check if your account has the ethers specified into genesis.json>alloc 63 | # RUN geth --datadir . --dev --exec "eth.getBalance(eth.coinbase)" console 64 | 65 | # "--ipcpath", "/datadir/geth.ipc", 66 | # VOLUME /datadir 67 | 68 | EXPOSE 8545 69 | EXPOSE 30303 70 | # TODO - check: port 30303 needed? 71 | 72 | ENTRYPOINT ["/usr/bin/geth", "--datadir", ".", "--password", "config/password.txt", "--unlock", "0", "--dev", "--rpc", "--rpcaddr", "0.0.0.0", "js", "./dist/geth_mine.js"] 73 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Ethereum DEVnet Container 2 | 3 | One geth node, based on Ubuntu 16.04 LTS 4 | 5 | #### Features: 6 | 7 | - Automatic address generation (generates a new coinbase address) 8 | - Genesis block setup (low difficulty for quick tx confirmations, high gas block limit) 9 | - Mining script (starts mining only when new transactions are present) 10 | 11 | ### Usage: 12 | 13 | docker pull makevoid/ethereum-geth-dev 14 | docker run -p 8545:8545 makevoid/ethereum-geth-dev 15 | 16 | 17 | It also has: 18 | 19 | - Node JS 20 | - Web3 as npm module 21 | - Coffeescript 22 | 23 | If you want a password different than `foo` please edit `config/password.txt` before running :D, also you'll may want to not automatically unlock the address via the geth `--password` arg/flag. 24 | 25 | Please take a look at the Dockerfile, it's quite simple and has few options (logging of some steps, regenerating the address...) 26 | 27 | 28 | 29 | @makevoid 30 | 31 | 32 | p.s. there are many repositories called `ethereum-geth-dev`, this is the latest version, you should check this out first but the others have some cool differences as well, the `ethereum-geth-dev-solc` one for example, that adds just an `apt-get-install solc` (coming from the ethereum sources, to add more on that, you can check also that you are actually pulling from the correct sources, that's why usually pulling from git and compiling (choose a stable version number maybe..) is usually the best version ) hf ;) 33 | -------------------------------------------------------------------------------- /coffeeify: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | coffee -c -o dist . 4 | -------------------------------------------------------------------------------- /config/genesis.json: -------------------------------------------------------------------------------- 1 | { 2 | "nonce": "0x000000000000002a", 3 | "timestamp": "0x0", 4 | "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 5 | "extraData": "0x0", 6 | "gasLimit": "0x800000000000", 7 | "difficulty": "0x400", 8 | "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", 9 | "coinbase": "0x0000000000000000000000000000000000000001", 10 | "alloc": { 11 | "ADDRESS": { 12 | "balance": "1606938044258990275541962092341162602522202993782792835301376" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /config/password.txt: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /console.sh: -------------------------------------------------------------------------------- 1 | sudo geth attach ipc:datadir/geth.ipc 2 | -------------------------------------------------------------------------------- /kill.sh: -------------------------------------------------------------------------------- 1 | docker kill $(docker ps -a -q --filter ancestor=ethereum/geth --filter status=running) 2 | -------------------------------------------------------------------------------- /lib/geth_mine.coffee: -------------------------------------------------------------------------------- 1 | # geth_mine.coffee - activate mining to mine pending transactions - forked by embark-framework 2 | # 3 | 4 | # library (from underscore) 5 | 6 | now = Date.now or -> 7 | (new Date).getTime() 8 | 9 | debounce = (func, wait) -> 10 | timeout = undefined 11 | args = undefined 12 | context = undefined 13 | timestamp = undefined 14 | result = undefined 15 | 16 | later = -> 17 | last = now() - timestamp 18 | if last < wait and last >= 0 19 | timeout = setTimeout(later, wait - last) 20 | else 21 | timeout = null 22 | result = func.apply(context, args) 23 | if !timeout 24 | context = args = null 25 | return 26 | 27 | -> 28 | context = this 29 | args = arguments 30 | timestamp = now() 31 | if !timeout 32 | timeout = setTimeout(later, wait) 33 | result 34 | 35 | # code 36 | 37 | eth = web3.eth 38 | 39 | do -> 40 | console.log 'geth_mine.js: start' 41 | console.log "node infos: #{JSON.stringify admin.nodeInfo}" 42 | 43 | config = 44 | threads: 8 45 | 46 | old_geth = admin.nodeInfo.name.match /^Geth\/v1\.3/ 47 | 48 | miner_stop = -> 49 | if old_geth 50 | miner.stop config.threads 51 | else 52 | miner.stop() 53 | 54 | miner_start = -> 55 | if old_geth 56 | miner.start config.threads 57 | else 58 | miner.start() 59 | 60 | main = -> 61 | miner_stop() 62 | 63 | startTransactionMining() 64 | 65 | pendingTransactions = -> 66 | if !eth.pendingTransactions 67 | txpool.status.pending or txpool.status.queued 68 | else if typeof eth.pendingTransactions == 'function' 69 | eth.pendingTransactions().length > 0 70 | else 71 | eth.pendingTransactions.length > 0 || eth.getBlock('pending').transactions.length > 0 72 | 73 | ifNoPendingTransactions = (callback) -> 74 | if !pendingTransactions() 75 | callback() 76 | 77 | 78 | stillMining = (callback) -> 79 | miner.hashrate > 0 80 | 81 | ifNotMiningDo = (callbackWhenInactive) -> 82 | if !stillMining() 83 | callbackWhenInactive() 84 | 85 | ifNoPendingTransactionsDeb = debounce ifNoPendingTransactions, 200 86 | ifNotMiningDoDeb = debounce ifNotMiningDo, 200 87 | 88 | startTransactionMining = -> 89 | eth.filter('pending').watch -> 90 | ifNotMiningDoDeb -> 91 | console.log '== Pending transactions! Looking for next block...' 92 | miner.start config.threads 93 | 94 | eth.filter('latest').watch -> 95 | ifNoPendingTransactionsDeb -> 96 | console.log '== No transactions left. Stopping miner...' 97 | miner.stop() 98 | 99 | main() 100 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "license": "Unlicense", 3 | "repository": "none", 4 | "description": "-", 5 | "dependencies": { 6 | "web3": "^0.17.0-alpha" 7 | }, 8 | "script": { 9 | "start": "node dist/app.js" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /prepare_genesis: -------------------------------------------------------------------------------- 1 | coinbase=$(geth --datadir . --dev --rpc --rpcaddr 0.0.0.0 --exec eth.coinbase console) 2 | echo "Coinbase: $coinbase" 3 | sed -i s/\"ADDRESS\"/$coinbase/g config/genesis.json 4 | echo "Coinbase written in genesis.json file." 5 | -------------------------------------------------------------------------------- /prepare_genesis.coffee: -------------------------------------------------------------------------------- 1 | # Web3 = require "web3" 2 | # fs = require 'fs' 3 | # 4 | # host = "http://localhost:8545" 5 | # web3 = new Web3(new Web3.providers.HttpProvider host) 6 | # eth = web3.eth 7 | 8 | coinbase = eth.coinbase 9 | 10 | genesisPath ='./config/genesis.json' 11 | genesis = fs.readFileSync genesisPath 12 | genesis.replace "ADDRESS", coinbase 13 | fs.writeFileSync genesisPath, genesis 14 | 15 | console.log "-----------------------------" 16 | console.log "Balance:" 17 | console.log "-----------------------------" 18 | console.log eth.getBalance(eth.coinbase) 19 | console.log "-----------------------------" 20 | 21 | process.exit 0 22 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | docker build -t='ethereum/geth' . && \ 2 | 3 | docker run -p 8545:8545 ethereum/geth 4 | 5 | # named datadir - good interop with other containers, they can all connect via /datadir/geth.ipc 6 | # 7 | # 8 | # additional notes: 9 | # 10 | # 11 | # You will end up with geth.ipc being created here (on linux): 12 | # 13 | # /var/lib/docker/volumes/datadir/_data 14 | # 15 | -------------------------------------------------------------------------------- /run_localdir.sh: -------------------------------------------------------------------------------- 1 | sudo rm -f $PWD/datadir/geth.ipc && \ 2 | 3 | docker build -t='ethereum/geth' . && \ 4 | 5 | docker run -p 8545:8545 -v $PWD/datadir:/datadir ethereum/geth 6 | 7 | # this uses local datadir (unfortunately it doesn't get shared well with other containers) 8 | -------------------------------------------------------------------------------- /screenshots/main.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makevoid/ethereum-geth-dev/8e327de9736f1ca43566f56cb7531411bb1d7c42/screenshots/main.jpg --------------------------------------------------------------------------------