-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransfer.ts
63 lines (41 loc) · 1.46 KB
/
transfer.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {
Connection,
Transaction,
SystemProgram,
sendAndConfirmTransaction,
PublicKey,
} from "@solana/web3.js";
import "dotenv/config"
import { getKeypairFromEnvironment } from "@solana-developers/helpers";
//get an argument passed
const suppliedToPubkey = process.argv[2] || null;
if (!suppliedToPubkey) {
console.log(`Please provide a public key to send to`);
process.exit(1);
}
//loaded key pair
const senderKeypair = getKeypairFromEnvironment("SECRET_KEY");
console.log(`suppliedToPubkey: ${suppliedToPubkey}`);
const toPubkey = new PublicKey(suppliedToPubkey);
//connection establishment
const connection = new Connection("https://api.devnet.solana.com", "confirmed");
console.log(
`✅ Loaded our own keypair, the destination public key, and connected to Solana `
);
// npx esrun transfer.ts ExriryaCnC49HeRu1rZnqeevYuXHcQajr1qP34Zu4MtS>
const transaction = new Transaction();
const LAMPORTS_TO_SEND = 5000;
const sendSolInstruction = SystemProgram.transfer({
fromPubkey: senderKeypair.publicKey,
toPubkey,
lamports: LAMPORTS_TO_SEND,
});
transaction.add(sendSolInstruction);
const signature = await sendAndConfirmTransaction(connection, transaction, [
senderKeypair,
]);
console.log(
`💸 Finished! Sent ${LAMPORTS_TO_SEND} to the address ${toPubkey}. `
);
console.log(`Transaction signature is ${signature}!`); // which was signed by sender
/// my address : ExriryaCnC49HeRu1rZnqeevYuXHcQajr1qP34Zu4MtS