current position:Home>The Syntax version of Ethereum DAPP development practical video tutorial?

The Syntax version of Ethereum DAPP development practical video tutorial?

2022-02-03 20:53:49 Q & A of Denglian community

image.png Reference resources “51CTO watch DAPP” Developing actual combat , Because the video tutorial is recorded early , In the process of learning and writing, with the current WEB3.js Different versions , There are multiple methods during the execution of the browser, which cannot be found , Source code attached , Please also advise which methods need to be modified , Can run through as soon as possible .image.png

<html><head>  <meta charset="UTF-8">  <title>First DAPP Demo</title>  <link rel="stylesheet" type="text/css" href="main.css">  <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script></head><body>  <div class="container">    <h1>First DAPP Demo</h1>    <h2 id="info"></h2>    <label> full name :</label>    <input id="name" type="text">    <label> Age :</label>    <input id="age" type="text">    <button id="button"> Update the content </button>  </div>  <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>  <script>    console.log("web3:" + web3);    if (typeof web3 !== 'undefined') {      web3 = new Web3(web3.currentProvider);    } else {      web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));    }    // Get contract variables     var infoContract = new web3.eth.Contract([{        "constant": true,        "inputs": [],        "name": "getInfo",        "outputs": [{            "name": "",            "type": "string"          },          {            "name": "",            "type": "uint256"          }        ],        "payable": false,        "stateMutability": "view",        "type": "function"      },      {        "constant": false,        "inputs": [{            "name": "_name",            "type": "string"          },          {            "name": "_age",            "type": "uint256"          }        ],        "name": "setInfo",        "outputs": [],        "payable": false,        "stateMutability": "nonpayable",        "type": "function"      }    ]);    var info = infoContract.at('0xda873b8dd76c861723e869269bc13a5a2999208f');    info.getInfo(function(error, result) {      if (!error) {        $("#info").html(result[0] + ' ( ' + result[1] + ' years old )');      }    });    $("#button").click(function() {      var name = $("#name").var();      var age = $("#age").var();      info.setInfo(name, age, function(error, result) {        if (!error) {          console.console.log("set ok");;        }      })    });  </script></body></html>



Take the answer 1:

Code updated :

see : https://github.com/xilibi2003/DAppDemos/




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

Random recommended