gpt4 book ai didi

python - geth ethereum 客户端连接到 ganache

转载 作者:太空宇宙 更新时间:2023-11-04 04:23:59 28 4
gpt4 key购买 nike

我想在一个网络中的不同计算机上设置一个私有(private)的以太坊测试网。

我有我的私有(private)计算机,其 web3.py 实现已连接到 Ganachi 测试网。我可以在我的程序中使用 solc 编译器从用 python 编写的程序部署智能合约。

现在我想在虚拟机和树莓派上设置两个不同的以太坊节点。我在 VM 上安装了 geth,但我不明白如何将 VM 与我计算机上运行的 Ganache 连接。

这是设置:

RPC 服务器 Ganachi:http://127.0.0.1:7545
网络 ID = 5777

我尝试使用此命令将 geth 节点与 ganache 连接:

geth --port 5000 --networkid 5777 --rpc --rpcport 7545 --rpcaddr 127.0.0.1 --rpccorsdomain '*' --rpcapi'eth,net,web3,personal' --testnet

它开始运行并写出这些信息
...启动对等节点
...分配的缓存和文件句柄
...从内存数据库中持久化 trie
...初始化链配置
...初始化以太坊协议(protocol)
...新建本地节点记录
...打开IPC端点
...HTTP 端点已打开
...开始P2P网络
...新建本地节点记录

当我启动我的程序时,VM 上没有显示任何内容,当我想向我在 VM 上创建的帐户发送交易时,我看不到其他余额。

这是我在本地计算机上的交易代码:

w3.eth.sendTransaction({'from': '0xC4AEe6dBE1BF2461776f48a4Ca0E06E39dE08bB6', 'value': wei_value, 'to': w3.toChecksumAddress('0xbdb3c3a7a0949b0aab9346e858f85fa8e3764733')})

交易完成,以太币从 ganache GUI 中的账户中提取。

但是当我使用这段代码在 VM 上测试帐户时:

geth --port 5000 --networkid 5777 --rpc --rpcport 7545 --rpcaddr 127.0.0.1 --testnet console

eth.getBalance(w3.toChecksumAddress('0xbdb3c3a7a0949b0aab9346e858f85fa8e3764733')})

输出为 0!

有人可以帮助我将 VM geth 连接到我的计算机 Ganache 吗?

VM 和我的电脑通过 VPN 连接。例如,当我将 Ganachi 中的设置更改为 http://0.0.0.0:7545当我更改行时,我的 python 代码出现错误:

provider = HTTPProvider('http://127.0.0.1:7545')

provider = HTTPProvider('http://0.0.0.0:7545')

出现此错误后:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=7545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000000004AC1128>: Failed to establish a new connection: [WinError 10049] Die angeforderte Adresse ist in diesem Kontext ungültig',))

我不知道该怎么办。

最佳答案

Ganache 在您的机器上模拟以太坊的本地实例。它用于本地开发,与您的 geth 节点不兼容。如果您想设置一个本地以太坊网络,您可以在本地机器和虚拟机上同时设置一个 geth 节点,在本地机器上设置两个 geth 节点,或者在虚拟机上设置两个 geth 节点。

关于python - geth ethereum 客户端连接到 ganache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53871309/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com