ContractObj not found in JavaScript

41 views Asked by At

$(document).ready(function(){

web3c = new Web3(ethereum);

const contractAddress="0x6eACA1A0406Def265a1ccbb193e09DA4Fd93635D"; const contractABI= [ { "inputs": [ { "internalType": "string", "name": "messageData", "type": "string" } ], "stateMutability": "view", "type": "function", "constant": true } ],

ContractObj = new web3c.eth.Contract(contractABI,contractAddress);

})

async function setData(){ value = document.getElementById("dataValue").value; tx= await ContractObj.methods.storeData(value).send({from: ethereum.selectedAddress}); console.log(tx); } async function getData(){ result = await ContractObj.methods.getData().call(); console.log(result); alert("Result "+ result); }

Here ContractObj not defined error occuring ...I am a beginner..Anyone pls help

1

There are 1 answers

0
Halil İbrahim Yücel On

change

ContractObj = new web3c.eth.Contract(contractABI,contractAddress);

to

let ContractObj = new web3c.eth.Contract(contractABI,contractAddress);

or

initialize ContractObj as a variable above your code.