Send Transaction to Solana Program 2

PHOTO EMBED

Tue Mar 14 2023 22:21:14 GMT+0000 (Coordinated Universal Time)

Saved by @luisjdominguezp #typescript

import * as web3 from "@solana/web3.js";
const BN = require ("bn.js");
const connection = new web3.Connection(web3.clusterApiUrl("devnet"));

async function main() {
    const key: Uint8Array = Uint8Array.from([PRIVATE KEY del que paga]);
    const signer: web3.Keypair = web3.Keypair.fromSecretKey(key);

    let programId: web3.PublicKey = new web3.PublicKey("Tu ProgramId");
    const data: Buffer = Buffer.from(
        Uint8Array.of(0, ...new BN(VALOR ENTERO DE 8 BITS).toArray("le",8))
    );

    let transaction: web3.Transaction = new web3.Transaction();
    transaction.add(
        new web3.TransactionInstruction({
            keys: [],
            programId,
            data
        })
    );
    await web3.sendAndConfirmTransaction(
        connection, transaction, [signer])
        .then((sig) => {
            console.log("signature:{}",sig);
        });
}

main()
content_copyCOPY