在Ubuntu下搭建自己的以太坊私有链

最近要对链及链上应用进行压测,为了方便操作及分析问题,就自己搭建了一个eth私链。当前版本安装官方指引发现有卡点,于是决定整理一个文档,为其他有需要的朋友提供便捷操作,节约时间。

一、环境配置

linux操作系统:Ubuntu 20.04.6 LTS (Focal Fossa)

go version: go1.21.3

Geth version:1.11.6

文档地址:

Go: https://golang.org/dl/

ethereum git地址:GitHub - ethereum/go-ethereum: Go implementation of the Ethereum protocol

Geth官方安装文档:Installing Geth | go-ethereum

Geth指令文档:JavaScript Console | go-ethereum

安装好Geth后,通过geth --help可以查看各指令作用和默认值

官方私链构建文档:启动一条以太坊私链 — 以太坊的指南针 1.0.0 documentation

chainList地址:ChainList

go安装忽略。

二、安装Geth

Geth是以太坊的客户端,其全称是go-ethereum。以太坊的客户端用于接入以太坊网络,进行账户管理、交易、挖矿、智能合约部署开发等相关的操作。目前有多种语言实现的客户端,Geth是用Go语言编写的,支持接入以太坊网络并成为一个完整节点。也可作为一个 HTTP-RPC 服务器对外提供 JSON-RPC 接口。

Geth的安装有两种方式:

  1. 直接下载程序进行安装(不通,仅作为记录)
  2. 通过编译源码安装(通过)。

1.直接下载程序安装Geth

1.1 下载软件包

执行如下命令:

sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum
 

完成后,执行 geth --help可以看到Geth的版本和命令参数等信息:

NAME:
   geth - the go-ethereum command line interface
​
USAGE:
   geth [global options] command [command options] [arguments...]
​
VERSION:
   1.13.15-stable-c5ba367e
​
COMMANDS:
   account                Manage accounts
   attach                 Start an interactive JavaScript environment (connect to node)
   console                Start an interactive JavaScript environment
   db                     Low level database operations
   dump                   Dump a specific block from storage
   dumpconfig             Export configuration values in a TOML format
   dumpgenesis            Dumps genesis block JSON configuration to stdout
   export                 Export blockchain into file
   export-history         Export blockchain history to Era archives
   import                 Import a blockchain file
   import-history         Import an Era archive
   import-preimages       Import the preimage database from an RLP stream
   init                   Bootstrap and initialize a new genesis block
   js                     (DEPRECATED) Execute the specified JavaScript files
   ....

1.2 创世块配置

创建工作目录:

# 创建私有链的目录
mkdir /data/ethprvychain
mkdir /data/ethprvychain/chaindata
#创建账户
cd /data/ethprvychain
geth account new --datadir chaindata
#然后会提示输入密码,我这里输入的是123456

console显示:

root@qa-op-stack-compile-168-3-250:/data/ethprvychain# geth account new --datadir chaindata/
INFO [05-09|15:27:18.165] Maximum peer count                       ETH=50 total=50
INFO [05-09|15:27:18.166] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
Your new account is locked with a password. Please give a password. Do not forget this password.
Password: 
Repeat password: 
​
Your new key was generated
​
Public address of the key:   0xdf5431f021fc90381b72A87797C552cCE4225cFE
Path of the secret key f
  • 25
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装Ubuntu系统 首先需要在服务器上安装Ubuntu系统(建议使用16.04及以上版本)。可以使用云服务器或者本地安装。 2. 安装Geth Geth是以太坊的官方客户端,可以用于搭建私有链和联盟链。可以使用以下命令安装: sudo add-apt-repository -y ppa:ethereum/ethereum sudo apt-get update sudo apt-get install -y ethereum 安装完成后,可以使用以下命令查看版本号: geth version 3. 创建创世块 首先需要创建创世块,创世块是区块链的第一个区块,包含了一些初始化的信息,如初始账户、初始余额、挖矿难度等。可以使用以下命令创建创世块: geth --datadir /path/to/chaindata init /path/to/genesis.json 其中,/path/to/chaindata为存储区块链数据的路径,/path/to/genesis.json为创世块的配置文件。 4. 启动节点 使用以下命令启动节点: geth --datadir /path/to/chaindata --networkid 1234 --nodiscover --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpcapi "eth,web3,personal,net" console 其中,/path/to/chaindata为存储区块链数据的路径,--networkid指定联盟链的ID,--nodiscover禁用节点发现功能,--rpc启用RPC服务,--rpcaddr指定RPC服务监听的IP地址,--rpcport指定RPC服务监听的端口号,--rpcapi指定可用的RPC接口,console表示启动控制台。 5. 创建账户 在控制台中使用以下命令创建账户: personal.newAccount("password") 其中,password为账户的密码。 6. 启动挖矿 使用以下命令启动挖矿: miner.start() 7. 部署智能合约 使用Solidity编写智能合约代码,并使用Remix或Truffle等工具进行编译和部署。 以上就是在Ubuntu系统上搭建以太坊联盟链的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值