[英]Using Hardhat to deploy smart contract to local Polygon node
我按照本教程学习了如何使用 HARDHAT 在 Polygon tes.net 上部署智能合约(它工作得很好)。
现在我想在我的本地 Polygon 区块链实例上运行一些测试,该实例在我的本地计算机(有 4 个节点)上运行并且工作正常。 我知道它有效,因为我可以通过 jsonRPC 和 gRPG 对其进行操作,查询余额、状态等。
所以,在我的 hardhat.config.js 中我有这个设置:
require("@nomiclabs/hardhat-ethers");
module.exports = {
defaultNetwork: "matic",
networks: {
hardhat: {
},
matic: {
url: "http://localhost:10002"
}
},
solidity: {
version: "0.8.0",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts"
},
mocha: {
timeout: 20000
}
}
然后我编译并尝试部署 Hardhat 的示例脚本:
$ npx hardhat compile
>Downloading compiler 0.8.0
>Compiled 2 Solidity files successfully
$ npx hardhat run scripts/sample-script.js --network matic
>ProviderError: the method eth_accounts does not exist/is not available
> at HttpProvider.request (/home/edu/projects/test-hardhat->polygon/node_modules/hardhat/src/internal/core/providers/http.ts:74:19)
> at GanacheGasMultiplierProvider.request (/home/edu/projects/test-hardhat->polygon/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:312:34)
似乎 Hardhat 正在调用我的 Polygon-Edge 本地区块链中不存在的方法 eth_accounts。
我究竟做错了什么?
提前致谢
好问题...在对同一问题进行故障排除时遇到了您的问题。 我正在运行polygon-edge server --dev...
并且无法使用 hardhat 或 truffle 部署智能合约。 另一种方法是使用 Remix IDE 和你的钱包,根据项目的Does polygon-edge support smart contract?通过注入的 Web3 进行部署。 第411章讨论
在 Remix IDE 中部署和运行事务,选择环境并通过事务部署。
完成后,您将能够在您的钱包中审查和批准交易,然后通过交易部署合约。 稍等片刻,警惕骗子、假混音 IDE 克隆,或使用真实资金偶然将此交易部署到实时网络! 话虽如此:如果您尚未将 a.network 导入 Metamask,如何导入。 如果你需要一个有资金的账户,对我有用的是通过私钥向 Metamask 导入一个账户,其中我包含预挖货币。 为了检索私钥,我引用了我的验证节点的数据文件夹,该文件夹包含$data-dir/consensus/validator.key
文件中的私钥。
关于实际错误和web3js..错误信息是准确的。 如果您重新访问引用JSON RPC 命令的多边形边缘文档,请注意缺少 eth_accounts 方法调用。 这对于依赖 web3.eth.getAccounts() 调用设置进行合约部署的底层节点模块来说是有问题的,进而影响 truffle 和 hardhat。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.