Error: This action requires a connected wallet to sign the transaction. Please pass a valid signer to the SDK.
Hi - I keep getting the following error:
Error: This action requires a connected wallet to sign the transaction. Please pass a valid signer to the SDK.
My wallet is connected though (address is available). But useWriteContract is failing.
can you share the code you're using? @heycryptobob
Hi, same here:
const sdk = useSDK();
const connectWallet = useMetamask();
const connected = useConnect();
async function signIn() {
var payload;
try {
payload = await sdk?.auth.login("example.com"); // Throw "This action requires a connected wallet"
} catch (error) {
console.log(error)
return
}
// Make a request to the API with the payload.
const res = await (await fetch("/api/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ payload }),
})).json();
console.log(res)
// Sign in with the token.
signInWithCustomToken(auth, res.token)
.then(async (userCredential) => {
console.error("User Logged");
})
.catch((error) => {
console.error(error);
});
}
async function onConnect() {
console.log("Connect Wallet")
var connection;
if (!connected[0].data.connected) {
connection = await connectWallet();
}
console.log(connection);
if (connection?.error == null) {
console.log("Connection Succeed")
signIn();
} else {
console.log("Connection Error")
}
}
then call onConnect @nachoiacovino
@Gioxxy how are you connecting users wallets? also, are you on the latest version of the SDK (3.5.1)?
@Gioxxy how are you connecting users wallets? also, are you on the latest version of the SDK (3.5.1)?
When the user tap a "connect" button i call the onConnect function and then it prompts to me the Metamask connection request. After the wallet connection i assume that the useMetamask() hook complete the promise so that i can start the sdk.auth.login.
Yes i'm on the latest version.
Hi @Gioxxy, the issue here is that you're doing await connectWallet() - and then after that you call signIn(). The thought process here is that when you await connectWallet() it should wait until the wallet is connected, so then it seems odd that it's giving you the "requires a signer" error on the signIn function.
However, the way that it actually works underneath is that you actually can't await a metamask connection (at the moment) - so doing await connectWallet() doesn't actually wait until the metamask wallet is connected, hence you're calling signIn before the wallet actually connects.
The solution would be to have connectWallet in a separate function, and then allow users to click something else that does the signIn after (basically connect wallet + sign in need to be on separate clicks)
Hi @adam-maj, i've seen that also useConnect() status is wrong. It tells that the wallet is connected immediately after i tap connect on Metamask. Is there any event emitted by the sdk.auth that i can use to check if it has the signer?
@Gioxxy sdk.auth isn't the place where the signer is - but you should be able to use the useAddress hook and if that returns back an address to you, then you know that the user is connected, if it's undefined, then you know that it's not connected yet.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.