I wanna Run a function on my contract but ı can t do it
my first code ı try but it didnt work
/* Moralis init code */
const serverUrl = "https://c1qxv3e4auot.usemoralis.com:2053/server";
const appId = "gWSt6pWWgRsi8xRRDD18oE6WyBEKqQJodFOWu6nP";
Moralis.start({ serverUrl, appId });
/* Authentication code */
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.authenticate({ signingMessage: "Log in using Moralis" });
await Moralis.enableWeb3();
.then(function (user) {
console.log("logged in user:", user);
console.log(user.get("ethAddress"));
})
.catch(function (error) {
console.log(error);
});
}
}
async function getMember() {
let options = {
contractAddres:"0x8563571DA0702B8E02AA1f37e544efCa4Fdf37ea",
functionName:"getMember"
abi:[{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"getMember","outputs":[],"stateMutability":"payable","type":"function"}]
params:{
to : user.get("ethAddress")
}
msgValue: Moralis.Units.ETH(0.05)
}
await Moralis.executeFunction(options);
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-getMember").onclick = getMember;
document.getElementById("btn-logout").onclick = logOut;
its my main.js ı wanna run function on contract but didnt login or mint
Second attempt
const serverUrl = "https://c1qxv3e4auot.usemoralis.com:2053/server"; //Server url from moralis.io
const appId = "gWSt6pWWgRsi8xRRDD18oE6WyBEKqQJodFOWu6nP"; // Application id from moralis.io
Moralis.start({ serverUrl, appId });
const CONTRACT_ADDRESS = "0x8563571DA0702B8E02AA1f37e544efCa4Fdf37ea";
const contractAbi = [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getID","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"getMember","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"tag","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"set","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"}];
async function mint() {
let to = "0x5266fa5E039580504DEb90BC898D3841ABb67e23";
let amount = Moralis.Units.ETH(0.05);
window.web3 = await Moralis.enableWeb3();
window.contract = new web3.eth.Contract(contractAbi, CONTRACT_ADDRESS);
contract.methods
.getMember(to).send({ from: ethereum.selectedAddress, value: amount })
}
/* Authentication code */
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.authenticate({ signingMessage: "Log in Avantasy" })
.then(function (user) {
console.log("logged in user:", user);
console.log(user.get("ethAddress"));
let useraddres;
useraddres = user.get("ethAddress");
shortaddres = useraddres.slice(0,5) + "..." + useraddres.slice(39);
document.getElementById("btn-login").innerHTML = shortaddres;
})
.catch(function (error) {
console.log(error);
});
}else{
let useraddres;
useraddres = user.get("ethAddress");
shortaddres = useraddres.slice(0,5) + "..." + useraddres.slice(39);
document.getElementById("btn-login").innerHTML = shortaddres;
}
}
async function logout() {
await Moralis.User.logOut();
document.getElementById("btn-login").innerHTML = "Connect";
console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("getMember").onclick = mint;
document.getElementById("btn-logout").onclick = logout;