无法连接到节点http:// localhost:8545

问题描述 投票:0回答:2

问题截图: 我的系统目录中的Web3.min.js路径!

Web3.min.js从我的浏览器中的文件夹加载

web3.min.js的副本位于存在index.html文件的同一文件夹中。

代码已添加

节点的信息!我面临以下两个问题:

  1. 无法加载资源:web3.min.js:1 net :: ERR_CONNECTION_REFUSED
  2. 错误:无法连接到节点http://localhost:8545。 我的Index.html文件是 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" type="text/css" href="main.css"> </head> <body> <div class="container"> <h1>Coursetro Instructor</h1> <h2 id="instructor"></h2> <label for="name" class="col-lg-2 control-label">Instructor Name</label> <input id="name" type="text"> <label for="name" class="col-lg-2 control-label">Instructor Age</label> <input id="age" type="text"> <button id="button">Update Instructor</button> </div> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script> if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { // set the provider you want from Web3.providers web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); } web3.eth.defaultAccount = web3.eth.accounts[0]; var CoursetroContract = web3.eth.contract([ { "constant": false, "inputs": [ { "name": "_fName", "type": "string" }, { "name": "_age", "type": "uint256" } ], "name": "setInstructor", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getInstructor", "outputs": [ { "name": "", "type": "string" }, { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" } ]); var Coursetro=CoursetroContract.at('0x95712aa4ff464e56f76af55da6239a368c459ed4'); console.log(Coursetro); </script> </body> </html>
visual-studio-code localhost ethereum web3
2个回答
0
投票

如果要连接到本地节点:

你已经包含了jquery cdn,类似地包含来自web3_cdn链接的web3。您可以从链接下载一个文件,然后通过webapp连接该文件

<script type="text/javascript" src="web3.min.js"></script>

并确保在运行应用程序时,您的元掩码已禁用。 Metamask将web3对象直接注入到您的应用程序中。

如需参考,请查看其他答案link


-1
投票

我有这个问题,我解决了。

解决方案 :

您必须在文件夹项目中创建index.html和main.css,而不是在node_modules文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.