无法连接到节点 http://localhost:8545 [英] Couldn't connect to node http://localhost:8545

查看:61
本文介绍了无法连接到节点 http://localhost:8545的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在 index.html 文件所在的同一文件夹中复制 web3.min.js.

添加的代码

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

  1. 无法加载资源:web3.min.js:1 net::ERR_CONNECTION_REFUSED

  2. 错误:无法连接到节点 http://localhost:8545.

    我的 Index.html 文件是

    <html lang="zh-cn"><头><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>文档</title><link rel="stylesheet" type="text/css" href="main.css">

    <身体><div class="容器"><h1>Coursetro 讲师</h1><h2 id="教师"></h2><label for="name" class="col-lg-2 control-label">讲师姓名</label><input id="name" type="text"><label for="name" class="col-lg-2 control-label">讲师年龄</label><input id="age" type="text"><button id="button">更新讲师</button>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script><脚本>if (typeof web3 !== 'undefined') {web3 = new Web3(web3.currentProvider);} 别的 {//从 Web3.providers 设置你想要的提供者web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));}web3.eth.defaultAccount = web3.eth.accounts[0];var CoursetroContract = web3.eth.contract([{常数":假,输入":[{"name": "_fName",类型":字符串"},{姓名年龄",类型":uint256"}],"name": "setInstructor",输出":[],应付":假,"stateMutability": "不可支付",类型":功能"},{常数":真的,输入":[],"name": "getInstructor",输出":[{姓名": "",类型":字符串"},{姓名": "",类型":uint256"}],应付":假,"stateMutability": "视图",类型":功能"}]);var Coursetro=CoursetroContract.at('0x95712aa4ff464e56f76af55da6239a368c459ed4');控制台日志(Coursetro);</html>

解决方案

如果您连接到本地节点:

您已包含 jquery cdn,同样包含来自链接的 web3 web3_cdn.您可以从链接下载一个文件并通过

在您的 web 应用程序中连接该文件

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

并确保当您运行应用程序时,您的元掩码已被禁用.Metamask 将 web3 对象直接注入您的应用程序.

参考其他答案链接

Screenshot of the issues:
Web3.min.js path in my system directory!

Web3.min.js is loaded from folder in my browser

Copy of the web3.min.js in the same folder where index.html file is present.

Code added

info of the node! I am facing following two issues:

  1. Failed to load resource: web3.min.js:1 net::ERR_CONNECTION_REFUSED

  2. ERROR: Couldn't connect to node http://localhost:8545.

    My Index.html file is

    <!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>
    

解决方案

If you are connecting to a local node:

You have included jquery cdn, similarly include a web3 from the link web3_cdn. You can download one file from the link and connect the file in your webapp by

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

And make sure when you run the app your metamask is disabled. Metamask injects a web3 object right into your application.

For reference check the other answers link

这篇关于无法连接到节点 http://localhost:8545的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆