I have a smart contract that basically store a document and I integrated it with a user interface that let the user go to the website and search for that document .. very simple idea.
I want to let the user use my website without having a wallet since no gas require (only read)
I tried creating an instance of the contract:
var contract
var addresse = //my contract addresse;
var api = // api ;
contract = new web3.eth.contract(api, addresse);
but when a i tried to use the website it say:
(index):240 Uncaught TypeError: Cannot read property 'isEntity' of undefined
here my code:
var contract;
var addresse = "0xDf6E7A02DC7457B7C1c534159305662B63794958";
var api = [
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "stdID",
"type": "string"
}
],
"name": "deleteCertificate",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "certID",
"type": "string"
},
{
"internalType": "string",
"name": "stdID",
"type": "string"
},
{
"internalType": "string",
"name": "stdName",
"type": "string"
},
{
"internalType": "uint256",
"name": "nID",
"type": "uint256"
},
{
"internalType": "string",
"name": "collage",
"type": "string"
},
{
"internalType": "string",
"name": "stdGPA",
"type": "string"
},
{
"internalType": "string",
"name": "gradYear",
"type": "string"
}
],
"name": "newCertificate",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [
{
"internalType": "string",
"name": "stdID",
"type": "string"
}
],
"name": "getCartID",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "string",
"name": "certID",
"type": "string"
},
{
"internalType": "string",
"name": "stdID",
"type": "string"
}
],
"name": "getCertificateInfo",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "string",
"name": "stdID",
"type": "string"
}
],
"name": "isEntity",
"outputs": [
{
"internalType": "bool",
"name": "isIndeed",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]; contract = new web3.eth.contract(api, addresse);
function getDou(){
var certHolder = document.getElementById("certInput").value;
var isExist = contract.methods.isEntity(certHolder).call().then(function (result) {
if(result){
contract.methods.getCartID(certHolder).call().then(function(result){
document.getElementById("getDoc").innerHTML = result;
});
}else{
alert("The document does not exist!!");
location.reload();
}
}).catch(function (err) {
console.log(err.message);
});
}
note: the code work fine when I added this before the contract
web3 = new Web3(web3.currentProvider);
but i think this will not work for the users
web3 is not defined