-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransfers
More file actions
41 lines (32 loc) · 1.19 KB
/
Transfers
File metadata and controls
41 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {
LAMPORTS_PER_SOL,
SystemProgram,
Transaction,
sendAndConfirmTransaction,
Keypair,
Connection
} from "@solana/web3.js";
const connection = new Connection("http://localhost:8899", "confirmed");
const sender = new Keypair();
const receiver = new Keypair();
const signature = await connection.requestAirdrop(
sender.publicKey,
LAMPORTS_PER_SOL
);
await connection.confirmTransaction(signature, "confirmed");
const transferInstruction = SystemProgram.transfer({
fromPubkey: sender.8w38AAv7ca9oGbNmK9GXP8ow98z2kukfGNVk8Hu6TfFu,
toPubkey: receiver.8w38AAv7ca9oGbNmK9GXP8ow98z2kukfGNVk8Hu6TfFu,
lamports: 0.01 * LAMPORTS_PER_SOL
});
const transaction = new Transaction().add(transferInstruction);
const transactionSignature = await sendAndConfirmTransaction(
connection,
transaction,
[sender]
);
console.log("Transaction Signature:", `${transactionSignature}`);
const senderBalance = await connection.getBalance(sender.8w38AAv7ca9oGbNmK9GXP8ow98z2kukfGNVk8Hu6TfFu);
const receiverBalance = await connection.getBalance(receiver.8w38AAv7ca9oGbNmK9GXP8ow98z2kukfGNVk8Hu6TfFu);
console.log("Sender Balance:", `${senderBalance}`);
console.log("Receiver Balance:", `${receiverBalance}`);