-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_sol.js
37 lines (32 loc) · 944 Bytes
/
send_sol.js
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
import * as web3 from '@solana/web3.js';
(async () => {
// Connect to cluster
var connection = new web3.Connection(
web3.clusterApiUrl('devnet'),
'confirmed',
);
// Generate a new random public key
var from = web3.Keypair.generate();
var airdropSignature = await connection.requestAirdrop(
from.publicKey,
web3.LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);
// Generate a new random public key
var to = web3.Keypair.generate();
// Add transfer instruction to transaction
var transaction = new web3.Transaction().add(
web3.SystemProgram.transfer({
fromPubkey: from.publicKey,
toPubkey: to.publicKey,
lamports: web3.LAMPORTS_PER_SOL / 100,
}),
);
// Sign transaction, broadcast, and confirm
var signature = await web3.sendAndConfirmTransaction(
connection,
transaction,
[from],
);
console.log('SIGNATURE', signature);
})();