我使用solc版本^0.4.6的区块链项目。当给出是web3.eth.accounts的命令时,一直抛出错误。
web3.eth.accounts
未定义错误:无效的JSON响应:未定义在(E:\techdot-master\node_modules\web3\lib\web3\errors.js:38:16) at HttpProvider.send (E:\techdot-master\node_modules\web3\lib\web3\httpprovider.js:91:22) at RequestManager.send (E:\techdot-master\node_modules\web3\lib\web3\requestmanager.js:58:32) at Eth.get as accounts。
我试过阅读文档并尝试其他命令。仍然无法解决这个问题!
发布于 2022-03-15 15:09:44
“无效的JSON响应”意味着您没有连接到该节点。为了连接到节点,您需要一个提供程序。您可以获得一个个人账户并创建一个提供程序HdWalletProvider。
const HDWalletProvider = require("@truffle/hdwallet-provider");
const provider = new HDWalletProvider({
mnemonic: {
phrase: metamask_mnemonic,
},
providerOrUrl: ropsten_network,//infura endpoint here
});或者您使用的是ganache-cli。
const ganache = require('ganache-cli');
const provider = ganache.provider()然后创建web3
const web3 = new Web3(provider);我认为应该是getAccounts,而不是帐户
const accounts = await web3.eth.getAccounts();发布于 2022-03-15 10:40:32
我建议使用ehtersjs,使用它,一切都要容易得多。
https://stackoverflow.com/questions/71479568
复制相似问题