current position:Home>Invalid JSON RPC response

Invalid JSON RPC response

2022-02-03 22:39:04 Q & A of Denglian community

QQ20200423105154.pngQQ20200423112230.pngRemix Connect ganache Successfully in use Dapp Connect ganache Prompt that... Has been introduced web3 success

Here is the code

<!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">    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script></head><body>    <div class="container">        <h1>Info Contract</h1>        <h2 id="info"></h2>        <label for="name" class="col-lg-2 control-label">Name</label>        <input id="name" type="text">        <label for="name" class="col-lg-2 control-label">Age</label>        <input id="age" type="text">        <button id="button">Update Info</button>    </div>    <script>    var web3 = new Web3('HTTP://127.0.0.1:7545');    web3.setProvider('HTTP://127.0.0.1:7545');    console.log("web3 local provider" + web3);var infoContract = new web3.eth.Contract([    {        "constant": true,        "inputs": [],        "name": "getInfo",        "outputs": [            {                "internalType": "string",                "name": "",                "type": "string"            },            {                "internalType": "uint256",                "name": "",                "type": "uint256"            }        ],        "payable": false,        "stateMutability": "view",        "type": "function"    },    {        "constant": false,        "inputs": [            {                "internalType": "string",                "name": "_fname",                "type": "string"            },            {                "internalType": "uint256",                "name": "_age",                "type": "uint256"            }        ],        "name": "setInfo",        "outputs": [],        "payable": false,        "stateMutability": "nonpayable",        "type": "function"    }], '0x749F8152652638167f12b6421A7bA320739974aA');infoContract.methods.getInfo().call({from: '0x749F8152652638167f12b6421A7bA320739974aA'}, function(error, result){  if(!error)         {             $("#info").html(result[0]+' ('+result[1]+' years old)');             console.log(result);         }     else         console.error(error);});</script></body></html>



Take the answer 1:

Your code doesn't match the output ?

If you use metamask Need to use http Access to . You can see the of this article Node connection




copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202032238599519.html

Random recommended