以太坊开发:从环境搭建到交易发送全流程指南
1. Ganache 开发链操作
1.1 强制挖矿新块
可以通过 Ganache 的 JSON - RPC 接口发送特殊的 evm_mine 指令来强制其随时挖掘新块。此指令是 Ganache 特有的,并非标准 JSON - RPC API 的一部分。以下是示例代码:
// Check the current block number
await web3.eth.getBlockNumber()
1
// Force ganache to mine a new block
let provider = web3.currentProvider
let send = util.promisify(provider.send).bind(provider)
await send({ method: 'evm_mine' })
// Verify that the block number has increased
await web3.eth.getBlockNumber()
2
1.2 持久化开发链
默认情况下,Ganache 生成的所有链都是临时的,当 Ganache 进程停止时数据会丢失。可以通过 db 选项启动 Ganache,将其状态存储在本地文件夹中,操作步骤如下:
1. 创建本地文件夹:
$ mkdir -p ganachedb
超级会员免费看
订阅专栏 解锁全文
11

被折叠的 条评论
为什么被折叠?



