一、Geth私有链搭建
环境:ubuntu20.0.04
1.安装geth
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
2.创建创世块文件
vim genesis.json
{
"nonce" : "0x0000000000000042",
"difficulty" : "0x200",
"mixhash " : "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x0000000000000000000000000000000000000000" ,
"timestamp" : "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData" : "0x",
"gasLimit" : "0x2CD29c0",
"alloc": {},
"config" : {
"chainId" : 6500,
"homesteadBlock" : 0
}
}
3.初始化
geth --datadir "chain" init genesis.json
geth --identity "myetherum" --http --http.corsdomain "*" --datadir "chain" --port "30303" --http.api "db,eth,net,web3,personal,miner" --networkid 6500 console 2>1.txt
geth --identity "myetherum" --http --http.corsdomain "*" --datadir "chain" --port "30303" --http.api "db,eth,net,web3,personal,miner" --networkid 6500 console 2>1.txt
新链
二、Ganache(命令行)
安装
npm install -g ganache-cli
打开
ganache-cli
安装web3
npm install web3 -save
测试
vim test.js
var Web3 = require('web3');
console.log("tset");
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
console.log(web3.version);
三、Ganache(图形化)
点击save按钮,保存workspace,此时已启动对应端口为7545