Skip to content

Instantly share code, notes, and snippets.

@martincik
Created March 9, 2023 06:11
Show Gist options
  • Save martincik/22001572c443797bba8cf9218d4f6323 to your computer and use it in GitHub Desktop.
Save martincik/22001572c443797bba8cf9218d4f6323 to your computer and use it in GitHub Desktop.
Signing and sending Memo transaction instead of signed message
const nonce = await getCsrfToken();
if (!nonce) {
throw new Error("Missing nonce.");
}
const tx = new Transaction();
tx.add(
new TransactionInstruction({
programId: new PublicKey(
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
),
keys: [{ pubkey: publicKey, isSigner: true, isWritable: false }],
data: Buffer.from(nonce, "utf8"),
})
);
const blockHash = await connection.getLatestBlockhash("finalized");
tx.feePayer = publicKey;
tx.recentBlockhash = blockHash.blockhash;
const signedTransaction = await signTransaction(tx);
const signedTransactionSerialized = signedTransaction
.serialize({ requireAllSignatures: false })
.toString("hex");
await signIn("credentials", {
signedTransactionSerialized: signedTransactionSerialized,
pubkey: bs58.encode(publicKey.toBytes()),
redirect: true,
callbackUrl: searchParams?.get("from") ?? "/dashboard",
});
} catch (error) {
setError(error);
console.error(error);
toast({
message: error.message || "Failed to sign transaction",
type: "error",
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment