Skip to content

Instantly share code, notes, and snippets.

@fukaoi
Last active July 24, 2022 22:54
Show Gist options
  • Save fukaoi/61a29aac0717fce4219c86165780efcd to your computer and use it in GitHub Desktop.
Save fukaoi/61a29aac0717fce4219c86165780efcd to your computer and use it in GitHub Desktop.
solana-program-library-memo
const {
Keypair,
Transaction,
TransactionInstruction,
PublicKey,
Connection,
sendAndConfirmTransaction,
LAMPORTS_PER_SOL,
} = require("@solana/web3.js");
const sendMemo = async (conn, account) => {
const instruction = new TransactionInstruction({
keys: [{
pubkey: account.publicKey,
isSigner: true,
isWritable: true
}],
programId: new PublicKey("Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo"),
data: Buffer.from("solana memo node.js test"),
});
return await sendAndConfirmTransaction(
conn,
new Transaction().add(instruction),
[account],
{
commitment: "confirmed",
}
)
};
(async () => {
const conn = new Connection("https://api.devnet.solana.com");
const account = new Keypair();
const sig1 = await conn.requestAirdrop(account.publicKey, LAMPORTS_PER_SOL);
await conn.confirmTransaction(sig1);
console.log("airdrop done");
console.log("account: ", account.publicKey.toBase58());
const sig = await sendMemo(conn, account);
console.log('sig: ', sig);
})().catch(console.error);
@alexandr-kazakov
Copy link

It seems to me here keys: [], it will need to be a keys, not just a empty array.

@fukaoi
Copy link
Author

fukaoi commented Jun 27, 2022

@alexandr-kazakov

This code is a note I wrote as test code when I was a Solana beginner. When I look at it now, I see deprecated and strange things. You are right, keys is needed. Fixed.

By the way, you can use my solana-suite library to implement the memo function more simply, if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment