Just cannot get what seems like a simple input from html page to interact with a very simple contract to input data.
Started off trying to make this tutorial work: Interacting with a Smart Contract through Web3.js
Have been around the horn with old, current, workaround info on web3 installs. Getting tired and finally have given in and need some help. What am I missing or not seeing?
Contract works in remix by itself but cannot get the web page to interact.
code being used below -
pragma solidity ^0.5.0;
contract Coursetro {
string fName;
uint age;
function setInstructor(string memory _fName, uint _age) public {
fName = _fName;
age = _age;
}
function getInstructor() public view returns (string memory, uint) {
return (fName, age);
}
}
<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="node_modules/web3/dist/web3.min.js"></script>
</head>
<body>
<div class="container">
<h1>Course Info 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>
// Our future code here..
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 = new 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"
}
], '0xD3a07D67D352AD9543ab46CA07931f2c1F8b1822'
//'0x1e37941619bfb66fa436e345b8ff7bfb4603ac2e'
);
// var Coursetro = new CoursetroContract.at('0x1e37941619bfb66fa436e345b8ff7bfb4603ac2e');
console.log
</script>
</body>
</html>