interact with a smart contract without having a wallet

interact with a smart contract without having a wallet

Manage alerts

Loading saved threads...

iias121 · External communityPost link
External question — Ethereum Stack Exchange Author: iias121 Original post: https://ethereum.stackexchange.com/questions/80102 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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
Quote
Report
Adam Boudj · External communityPost link
External answer — Ethereum Stack Exchange Author: Adam Boudj Original post: https://ethereum.stackexchange.com/a/80103 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Ethers.js uses a different approach that I believe provides developers more flexibility. Try with this code after npm i ethers and renaming your variable api -> abi //Load ethers const ethers = require('ethers'); async function isEntity(entity) { // Connect to the network const provider = ethers.getDefaultProvider("homestead"); // The address of the smart contract const contractAddress = "0xDf6E7A02DC7457B7C1c534159305662B63794958"; // We connect to the Contract using a Provider, so we will only // have read-only access to the Contract const contract = new ethers.Contract(contractAddress, abi, provider); return await contract.isEntity(entity); }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Ethereum Stack Exchange Author: iias121 Source score (net votes, not local likes): 1 Original post: https://ethereum.stackexchange.com/questions/80102 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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

Cancel quote

Checking account access…