Hellow,
I would like to know if there are any way to call a function from a ethereum smart contract that isnt read-only with javascript. I only have found Moralis.EvmApi.utils.runContractFunction, but Im getting this error:
Moralis SDK Core Error: [C0006] Request failed, (400): Function mint
is not read only
Thank you
for write functions you can use web3 or ethers library with currently connected wallet that can be metamask for example
How can i βlinkβ the metamask account with which I autheticated to web3? I m currently logging in with this tutorial: https://docs.moralis.io/authentication-api/how-to-sign-in-with-metamask
there is this code here:
import { MetaMaskConnector } from "wagmi/connectors/metaMask";
import { useAccount, useConnect, useSignMessage, useDisconnect } from "wagmi";
import { useAuthRequestChallengeEvm } from "@moralisweb3/next";
function SignIn() {
const { connectAsync } = useConnect();
const { disconnectAsync } = useDisconnect();
const { isConnected } = useAccount();
const { signMessageAsync } = useSignMessage();
const { requestChallengeAsync } = useAuthRequestChallengeEvm();
const handleAuth = async () => {
if (isConnected) {
await disconnectAsync();
}
const { account, chain } = await connectAsync({
connector: new MetaMaskConnector(),
});
const { message } = await requestChallengeAsync({
address: account,
chainId: chain.id,
});
const signature = await signMessageAsync({ message });
console.log(signature);
};
return (
<div>
<h3>Web3 Authentication</h3>
<button onClick={handleAuth}>Authenticate via Metamask</button>
</div>
);
}
export default SignIn;
that is used to sign a message with current wallet application
maybe the documentation for wagmi can help you
https://wagmi.sh/examples/contract-write
Im going to check it. Thank you!
1 Like