2023-01-04 05:46:43 -08:00
|
|
|
import { Connection, Keypair, LAMPORTS_PER_SOL, SystemProgram, sendAndConfirmTransaction, Transaction, PublicKey } from "@solana/web3.js";
|
|
|
|
|
|
|
|
jest.setTimeout(60000);
|
|
|
|
|
|
|
|
test('send and confirm transaction', async () => {
|
|
|
|
const connection = new Connection('http://127.0.0.1:8890', 'confirmed');
|
|
|
|
const payer = Keypair.generate();
|
|
|
|
const toAccount = Keypair.generate().publicKey;
|
|
|
|
|
|
|
|
const airdropSignature = await connection.requestAirdrop(payer.publicKey, LAMPORTS_PER_SOL * 2);
|
2023-01-07 00:44:30 -08:00
|
|
|
console.log('airdrop signature ' + airdropSignature);
|
2023-01-04 05:46:43 -08:00
|
|
|
await connection.confirmTransaction(airdropSignature, 'finalized');
|
2023-01-07 00:44:30 -08:00
|
|
|
console.log('confirmed');
|
2023-01-04 05:46:43 -08:00
|
|
|
|
|
|
|
const transaction = new Transaction();
|
|
|
|
|
|
|
|
// Add an instruction to execute
|
|
|
|
transaction.add(
|
|
|
|
SystemProgram.transfer({
|
|
|
|
fromPubkey: payer.publicKey,
|
|
|
|
toPubkey: toAccount,
|
|
|
|
lamports: LAMPORTS_PER_SOL,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
await sendAndConfirmTransaction(connection, transaction, [payer]);
|
|
|
|
});
|