这个文档有吧 import solanaWeb3 from '@solana/web3.js'; // 设置交易的最近区块hash,用于标识交易的时间 const { blockhash,lastValidBlockHeight } = await connection.getLatestBlockhash("finalized"); console.log("blockhash",blockhash,"bestheight",lastValidBlockHeight)
// 构造指令
let instructions = [solanaWeb3.SystemProgram.transfer({
fromPubkey: keypair.publicKey,
toPubkey: new solanaWeb3.PublicKey("2jczRubmN9Vt4hjqJKWTwkyc8giJ2X1NAZLz5emc"),
lamports: 100000000
})]
// 构造message对象
const messageV0 = new solanaWeb3.TransactionMessage({
payerKey: keypair.publicKey,
recentBlockhash: blockhash,
instructions: instructions,
}).compileToV0Message();
// 构造交易并且签名
const vtransaction = new solanaWeb3.VersionedTransaction(messageV0)
vtransaction.sign([keypair])
let txhash = await connection.sendTransaction(vtransaction);
console.log("Transaction Signature: ", txhash);