Sign inSign up

fuming/geth-test

By fuming

•Updated almost 2 years ago

Geth client for test

Image
0

350

fuming/geth-test repository overview

⁠fuming/geth-test

My geth client for develop test.

Geth version: v1.11.6.

⁠Usage

⁠Start
⁠Command line
docker run -d -p 8545:8545 -p 8546:8546 -p 30303:30303 --name eth-test -e data_dir=/root/eth_data -v /root/eth_data fuming/geth-test:latest

After container started, you can attach geth console using:

docker exec -it eth-test /root/attach.sh
⁠Docker Compose

File docker-compose.yml:

version: '3.5'
services:
  geth-test:
    image: fuming/geth-test:v1.11.6
    container_name: geth-test
    ports:
      - "8545:8545" #RPC
      - "8546:8546" #WebSocket
      - "30303:30303/udp"
    volumes:
      - geth-data:/root/eth_data
      - dag-data:/root/.ethash
    environment:
      data_dir: /root/eth_data/
    
volumes:
  geth-data:
  dag-data:

Start container:

docker-compose up -d

After container started, you can attach geth console using:

docker exec -it geth-test /root/attach.sh
⁠Operate

Two accounts with almost unlimited balance are already built in, the passphrase for both accounts is 123456, you can see them command below on geth console:

> eth.accounts;

In a private network setting, a single CPU miner instance is more than enough for practical purposes as it can produce a stable stream of blocks at the correct intervals without needing heavy resources (consider running on a single thread, no need for multiple ones either). To start a geth instance for mining, run it with all your usual flags, extended by:

> miner.start(1);

Which will start mining blocks and transactions on a single CPU thread.

And also, you can mine only one block by using this:

miner.start(1);admin.sleepBlocks(1); miner.stop();

Send transaction:

> personal.unlockAccount(eth.accounts[0], "123456")

> eth.sendTransaction({ from: eth.accounts[0], to:eth.accounts[1], value: web3.toWei(1, "ether") } )

> web3.fromWei(eth.getBalance(eth.accounts[0]), 'ether')

Have fun!

⁠Source

File Dockerfile:

FROM ethereum/client-go:v1.14.11
LABEL MAINTAINER="[email protected]"
ENV data_dir /root/eth_data/
COPY entrypoint.sh /root/
COPY attach.sh /root/
COPY genesis.json /root/
COPY UTC--2021-01-14T03-06-22.416540000Z--47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce /root/
COPY UTC--2021-01-14T03-07-11.612118000Z--19dbca3be6358f474caea47a0f177a33afa5a1d2 /root/
WORKDIR /root/
RUN chmod +x entrypoint.sh
RUN chmod +x attach.sh
ENTRYPOINT ["/root/entrypoint.sh"]

File entrypoint.sh:

#!/bin/sh
mkdir -p $data_dir
if [ ${data_dir: -1} != "/" ]; then
    data_dir=$data_dir"/"
fi
geth --datadir $data_dir init /root/genesis.json
mv /root/UTC--2021-01-14T03-06-22.416540000Z--47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce $data_dir"keystore"
mv /root/UTC--2021-01-14T03-07-11.612118000Z--19dbca3be6358f474caea47a0f177a33afa5a1d2 $data_dir"keystore"
api="eth,net,web3,txpool,personal,ethash,miner,admin,debug"
addr="0.0.0.0"
networkid=666
identity="666"
geth --nodiscover --identity $identity --datadir $data_dir --allow-insecure-unlock --networkid $networkid --http --http.api $api --http.addr $addr --ws --ws.api $api --ws.addr $addr --ws.origins '*' --miner.etherbase '47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce'

File attach.sh:

#!/bin/sh
geth attach --datadir $data_dir

File genesis.json:

{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x672e1d71",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0xffffffffffff",
  "difficulty": "1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce",
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "alloc": {
    "0x47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce": {
      "balance": "0xffffffffffffffff"
    },
    "0x19dbca3be6358f474caea47a0f177a33afa5a1d2": {
      "balance": "0xffffffffffffffff"
    }
  }
}

File UTC--2021-01-14T03-06-22.416540000Z--47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce:

{"address":"47c9a59fe5d28ff862f8eaf5924dbc90af00b0ce","crypto":{"cipher":"aes-128-ctr","ciphertext":"3fd871d49cf8c477d043565b3a8bafdc8e229c43fc6fc448fe6065368cc6d234","cipherparams":{"iv":"2e85bed1e31dc6d09c6985f2b9b4bd87"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"638385b17830fe0495effa6f924b22d67be9b0c98b6d5c36ba36ce57c6c1094a"},"mac":"27fc10498073a194e68b3f35d91e940a4e1bddb22168fc9783cbb6e202624de4"},"id":"fd12612c-bbe0-4448-8961-666e2c81e4b3","version":3}

File UTC--2021-01-14T03-07-11.612118000Z--19dbca3be6358f474caea47a0f177a33afa5a1d2:

{"address":"19dbca3be6358f474caea47a0f177a33afa5a1d2","crypto":{"cipher":"aes-128-ctr","ciphertext":"14cb694a4d2cc2082a930456f90c61fe982e191197c97496324fe3b931ce1863","cipherparams":{"iv":"25ca29c835c69f52320feab50ad2f58f"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"f237b3eb3eb4b49d28bb0e22afda5bdab4d3d9f2015c9d63efc6fbaa0949f197"},"mac":"0e96315c3f303536aaa87e92cceb357a029b027fb4dcae1e11afe0d62328a45f"},"id":"7af1a435-8c41-4d25-9c10-1db406a11d6b","version":3}

Tag summary

Content type

Image

Digest

sha256:3a54d55e2…

Size

30 MB

Last updated

almost 2 years ago

docker pull fuming/geth-test:v1.11.6