GETH 搭建私链
Article Summary
GPT 4
1.下载客户端
在下载geth时,要注意版本不要太高,最新版本的geth不支持搭建私链。
这里是11.6版本。
2.准备创世块的配置文件
{
"config": {
"chainId": 10,
"homesteadBlock": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"eip155Block": 0,
"eip158Block": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0xffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc" : {}
}
3.初始化写入创世区块
geth init --datadir data1 genesis.json
4.启动geth
geth --datadir data1 --networkid 10 --http --http.addr 0.0.0.0 --http.port 8545 --http.corsdomain "*" --http.api "db,eth,net,web3,personal,web3" --port 30305 -allow-insecure-unlock console 2>>geth.log
- ./geth:这是执行 Geth 客户端的命令。
- –datadir data1:这个选项指定了数据目录的路径,Geth 将在这个目录中存储区块链数据和相关文件。
- –networkid 10:指定私有链的网络标识符,这个值用于在不同私有链之间进行区分。
- –http:启用 HTTP-RPC 通信接口,允许通过 HTTP 请求与 Geth 进行交互。
- –http.addr 0.0.0.0:设置 HTTP-RPC 服务监听的地址,0.0.0.0 表示允许来自任何 IP 地址的连接。
- –http.port 8545:指定 HTTP-RPC 服务的端口号,一般是 8545。
- –http.corsdomain “*”:配置允许跨域请求的域名,设置为 “*” 表示允许任何域名进行跨域请求。
- –http.api “db,eth,net,web3,personal,web3”:指定启用的 HTTP-RPC 接口,这里列出了一些常用的接口,包括数据库、以太坊操作、网络信息、Web3 功能和个人账户操作。
- –port 30305:设置 Geth 节点的 P2P 网络端口,用于节点间的通信。
- -allow-insecure-unlock:允许以不安全的方式解锁账户。这在测试环境中使用,允许在 HTTP-RPC 上发送解锁账户的请求,但在生产环境中不建议使用
web3.fromWei(eth.getBalance(eth.coinbase), “ether”);
参考网站
一步步教程:使用Geth在本地搭建私有以太坊区块链 - 哔哩哔哩 (bilibili.com)
Win10使用Geth客户端搭建以太坊私有链、连接可视化钱包 - 樹海 - 博客园 (cnblogs.com)
web3的异常
from web3 import Web3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\python\Python310\lib\site-packages\web3\__init__.py", line 1, in <module>
from eth_account import Account # noqa: E402,
File "D:\python\Python310\lib\site-packages\eth_account\__init__.py", line 1, in <module>
from eth_account.account import (
File "D:\python\Python310\lib\site-packages\eth_account\account.py", line 20, in <module>
from eth_keyfile import (
File "D:\python\Python310\lib\site-packages\eth_keyfile\__init__.py", line 7, in <module>
from eth_keyfile.keyfile import ( # noqa: F401
File "D:\python\Python310\lib\site-packages\eth_keyfile\keyfile.py", line 11, in <module>
from eth_keys import keys
File "D:\python\Python310\lib\site-packages\eth_keys\__init__.py", line 15, in <module>
from .main import ( # noqa: F401
File "D:\python\Python310\lib\site-packages\eth_keys\main.py", line 3, in <module>
from eth_utils import (
File "D:\python\Python310\lib\site-packages\eth_utils\__init__.py", line 86, in <module>
from .network import (
File "D:\python\Python310\lib\site-packages\eth_utils\network.py", line 49, in <module>
networks = initialize_network_objects()
File "D:\python\Python310\lib\site-packages\eth_utils\network.py", line 27, in initialize_network_objects
network_data = json.load(open_file)
File "D:\python\Python310\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
UnicodeDecodeError: 'gbk' codec can't decode byte 0x88 in position 247555: illegal multibyte sequence
解决方案
https://blog.csdn.net/weixin_44322508/article/details/134130583
在线挖矿
This piece of writing is an original article, utilizing theCC BY-NC-SA 4.0Agreement. For complete reproduction, please acknowledge the source as Courtesy ofxiaocai