Created
March 9, 2023 06:11
-
-
Save martincik/22001572c443797bba8cf9218d4f6323 to your computer and use it in GitHub Desktop.
Signing and sending Memo transaction instead of signed message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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