Known the contract address, and original code work fine, which per ethers.
How to utilize moralis to restructure existed code ?
const handleClaim: MouseEventHandler<HTMLButtonElement> = async (e) => {
if (is_connected === true) {
let contract = new ethers.Contract(address, abi, provider);
contract = contract.connect(signer);
let is_claim = await contract
.return_is_claim(msg_address)
.then((res: Promise<string>) => {
// console.log("merun", res); // merun false
return res;
});
if (is_claim === false) {
// It is functions NOT function
// let sigRes =
await contract.functions
.claim()
.then(
(res) => {
console.log("suc....", res);
},
(rej) => {
// console.log("rej...", rej);
if (rej.code === 4001) {
alert("user reject release privilege");
}
}
)
.catch((err) => {
console.log("catch err ", err);
})
.finally();
// console.log("run...", sigRes); // run... undefined, even user accepted sign, here is undefined, too. run... undefined
// bundle.js:617 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'claim') at handleClaim (bundle.js:617:33)
} else {
alert("you have claimed");
}
} else {
alert("pls connect your wallet first");
}
};