Last active
July 24, 2022 22:54
-
-
Save fukaoi/61a29aac0717fce4219c86165780efcd to your computer and use it in GitHub Desktop.
solana-program-library-memo
This file contains hidden or 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 { | |
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); |
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
It seems to me here
keys: [],
it will need to be a keys, not just a empty array.