0

'''

Document
<link rel="stylesheet" type="text/css" href="main.css">

<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
    <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>

   if (typeof web3 !=='undefined') {

web3 = new Web3(web3.currentProvider);

} else {
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
}

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"
}
]);
var Coursetro = CoursetroContract.at('0x5c6479Be2eD8cA2C6E1bbBDa86Aa60190923d72F');
    
console.log(Coursetro);
    Coursetro.getInstructor(function(error, result){
        if(!error)
            {
                $("#instructor").html(result[0]+' ('+result[1]+' years old)');
                console.log(result);
            }
        else
            console.error(error);
    });

    $("#button").click(function() {
        Coursetro.setInstructor($("#name").val(), $("#age").val());
    });
</script>
'''

this is the error I was getting, help me to complete this

0

I am not sure how .at(addr) works in front-end but you can connect to an already deployed contract in the following way using web3:

myContractInstance = new web3.eth.Contract(
  contractABI,
  contractDeployedAddress
);

I hope it helps.

5
  • yes,I Deployed my smart contract in remix ide and i took AbI and Contract address and placed in the html code Apr 7 at 16:04
  • I hope its working fine. Apr 7 at 16:13
  • it doesn't work,getting error{ await is only valid in async functions and the top level bodies of modules} Apr 9 at 6:01
  • Remove await in that case, updated my code. Apr 9 at 11:47
  • would you help me with the "set" funtion from my code? Apr 16 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.