当前位置: 首页 > 工具软件 > Cpp Ethereum > 使用案例 >

windows下搭建cpp-ethereum私有链

袁良弼
2023-12-01

 1.在编译出来的aleth.exe目录下创建一个创世块文件genesis.json:

{ 
 	"sealEngine": "Ethash", 
 	"params": { 
 		"accountStartNonce": "0x00", 
 		"maximumExtraDataSize": "0x20", 
 		"homesteadForkBlock": "0x00", 
 		"EIP150ForkBlock": "0x00", 
 		"EIP158ForkBlock": "0x00", 
 		"byzantiumForkBlock": "0x00", 
 		"constantinopleForkBlock": "0x00", 
 		"minGasLimit": "0x1388", 
 		"maxGasLimit": "7fffffffffffffff", 
 		"tieBreakingGas": false, 
 		"gasLimitBoundDivisor": "0x0400", 
 		"minimumDifficulty": "0x020000", 
 		"difficultyBoundDivisor": "0x0800", 
 		"durationLimit": "0x0d", 
 		"blockReward": "0x4563918244F40000", 
 		"networkID" : "0x454", 
 		"chainID": "0x01", 
 		"allowFutureBlocks" : true 
 	}, 
 	"genesis": { 
 		"nonce": "0x0000000000000042", 
 		"difficulty": "0x400000000", 
 		"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
 		"author": "0x0000000000000000000000000000000000000000", 
 		"timestamp": "0x00", 
 		"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
 		"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa", 
 		"gasLimit": "0x1388" 
 	}, 
 	"accounts": { 
 		"0000000000000000000000000000000000000001": { "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } }, 
 		"0000000000000000000000000000000000000002": { "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } }, 
 		"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } }, 
 		"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } }, 
 		"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp" } }, 
 		"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } }, 
 		"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } }, 
 		"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product" } } 
 	} 
 } 

2.打开cmd,进入aleth.exe目录,输入命令行开始挖矿:

aleth --config genesis.json -m on -v 5 --network-id 1108 --ipc --listen 30307 --port 30307 --db-path blockchain --private "mynet"

3.打开ethconsole进行连接,得到一个web3对象,然后就可以通过web3这个对象来操作了,关于web3的api可以参考http://web3js.readthedocs.io/en/1.0/index.html

NAME:
   aleth 1.5.0.dev0+commit.fbf30b71.dirty
USAGE:
   aleth [options]

WALLET USAGE:
   account list                                List all keys available in wallet
   account new                                 Create a new key and add it to wallet
   account update [<uuid>|<address> , ... ]    Decrypt and re-encrypt keys
   account import [<uuid>|<file>|<secret-hex>] Import keys from given source and place in wallet
   wallet import <file>                        Import a presale wallet

CLIENT MODE (default):
  --mainnet                               Use the main network protocol
  --ropsten                               Use the Ropsten testnet
  --private <name>                        Use a private chain
  --test                                  Testing mode; disable PoW and provide test rpc interface
  --config <file>                         Configure specialised blockchain using given JSON information

  -o [ --mode ] <full/peer>               Start a full node or a peer node (default: full)

  --ipc                                   Enable IPC server (default: on)
  --ipcpath <path>                        Set .ipc socket path (default: data directory)
  --no-ipc                                Disable IPC server
  --admin <password>                      Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up)
  -K [ --kill ]                           Kill the blockchain first
  -R [ --rebuild ]                        Rebuild the blockchain from the existing database
  --rescue                                Attempt to rescue a corrupt database

  --import-presale <file>                 Import a pre-sale key; you'll need to specify the password to this key
  -s [ --import-secret ] <secret>         Import a secret key into the key store
  -S [ --import-session-secret ] <secret> Import a secret session into the key store
  --master <password>                     Give the master password for the key store; use --master "" to show a prompt
  --password <password>                   Give a password for a private key

CLIENT TRANSACTING:
  --ask <wei>            Set the minimum ask gas price under which no transaction will be mined (default: 20000000000)
  --bid <wei>            Set the bid gas price to pay for transactions (default: 20000000000)
  --unsafe-transactions  Allow all transactions to proceed without verification; EXTREMELY UNSAFE

CLIENT MINING:
  -a [ --address ] <addr>         Set the author (mining payout) address (default: auto)
  -m [ --mining ] <on/off/number> Enable mining; optionally for a specified number of blocks (default: off)
  --extra-data arg                Set extra data for the sealed blocks

CLIENT NETWORKING:
  -b [ --bootstrap ]              Connect to the default Ethereum peer servers (default unless --no-discovery used)
  --no-bootstrap                  Do not connect to the default Ethereum peer servers (default only when --no-discovery is used)
  -x [ --peers ] <number>         Attempt to connect to a given number of peers (default: 11)
  --peer-stretch <number>         Give the accepted connection multiplier (default: 7)
  --public-ip <ip>                Force advertised public IP to the given IP (default: auto)
  --listen-ip <ip>(:<port>)       Listen on the given IP for incoming connections (default: 0.0.0.0)
  --listen <port>                 Listen on the given port for incoming connections (default: 30303)
  -r [ --remote ] <host>(:<port>) Connect to the given remote host (default: none)
  --port <port>                   Connect to the given remote port (default: 30303)
  --network-id <n>                Only connect to other hosts with this network id
  --peerset <list>                Space delimited list of peers; element format: type:publickey@ipAddress[:port]
                                          Types:
                                          default     Attempt connection when no other peers are available and pinning is disabled
                                          required    Keep connected at all times

  --no-discovery                  Disable node discovery; implies --no-bootstrap
  --pin                           Only accept or connect to trusted peers

BENCHMARKING MODE:
  -M,--benchmark               Benchmark for mining and exit
  --benchmark-warmup <seconds> Set the duration of warmup for the benchmark tests (default: 3)
  --benchmark-trial <seconds>  Set the duration for each trial for the benchmark tests (default: 3)
  --benchmark-trials <n>       Set the number of trials for the benchmark tests (default: 5)

MINING CONFIGURATION:
  -C,--cpu                   When mining, use the CPU
  -t, --mining-threads <n>   Limit number of CPU/GPU miners to n (default: use everything available on selected platform)
  --current-block            Let the miner know the current block number at configuration time. Will help determine DAG size and required GPU memory
  --disable-submit-hashrate  When mining, don't submit hashrate to node

IMPORT/EXPORT MODES:
  -I [ --import ] <file>      Import blocks from file
  -E [ --export ] <file>      Export blocks to file
  --from <n>                  Export only from block n; n may be a decimal, a '0x' prefixed hash, or 'latest'
  --to <n>                    Export only to block n (inclusive); n may be a decimal, a '0x' prefixed hash, or 'latest'
  --only <n>                  Equivalent to --export-from n --export-to n
  --format <binary/hex/human> Set export format
  --dont-check                Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid
  --download-snapshot <path>  Download Parity Warp Sync snapshot data to the specified path
  --import-snapshot <path>    Import blockchain and state data from the Parity Warp Sync snapshot

VM OPTIONS:
  --vm <name>|<path> (=legacy) Select VM implementation. Available options are: interpreter, legacy.
  --evmc  <option>=<value>     EVM-C option

LOGGING OPTIONS:
  -v [ --log-verbosity ] <0 - 4>        Set the log verbosity from 0 to 4 (default: 2).
  --log-channels <channel_list>         Space-separated list of the log channels to show (default: show all channels).
  --log-exclude-channels <channel_list> Space-separated list of the log channels to hide.

GENERAL OPTIONS:
  -d [ --db-path ] <path> Load database from path (default: C:\Users\Administrator\AppData\Roaming\Ethereum)
  -V [ --version ]        Show the version and exit
  -h [ --help ]           Show this help message and exit

 

 类似资料: