02. 最佳实践

 


参考

https://geth.ethereum.org/docs/getting-started/dev-mode

在开发模式下启动 Geth

您可以使用该--datadir选项指定一个数据目录来维护两次运行之间的状态,否则,数据库是临时的并且在内存中:

mkdir test-chain-dir

对于本指南,在开发模式下启动 geth,并启用RPC以便您可以将其他应用程序连接到 geth。在本指南中,我们使用基于 Web 的以太坊 IDE Remix,因此也允许其域接受跨域请求。

geth --datadir test-chain-dir --http --dev --http.corsdomain "https://remix.ethereum.org,http://remix.ethereum.org"

从另一个终端窗口连接到节点上的 IPC 控制台:

geth attach <IPC_LOCATION>

一旦 geth 在开发模式下运行,您就可以像当 geth 以其他方式运行时一样与它进行交互。

例如,创建一个测试帐户:

> personal.newAccount()

并将以太币从 coinbase 转移到新账户:

> eth.sendTransaction({from:eth.coinbase, to:eth.accounts[1], value: web3.toWei(0.05, "ether")})

并查看账户余额:

> eth.getBalance(eth.accounts[1])

如果你想用真实的区块时间测试你的 dapps,请在使用参数--dev.period启动开发模式时使用该选项--dev.period 14

geth --datadir test-chain-dir --http --http.addr 0.0.0.0 --dev.period 14 --http.corsdomain "https://remix.ethereu
m.org,http://remix.ethereum.org"

宿主机无法访问容器

添加 --http.addr 0.0.0.0

geth --datadir test-chain-dir --http --http.addr 0.0.0.0 --dev --http.corsdomain "https://remix.ethereum.org,http://remix.ethereum.org"
posted @   1766Af  阅读(67)  评论(0编辑  收藏  举报
编辑推荐:
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
点击右上角即可分享
微信分享提示