-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend-transaction.ts
39 lines (28 loc) · 1.03 KB
/
send-transaction.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
import {
Commitment,
Connection, Keypair,
LAMPORTS_PER_SOL,
PublicKey, SystemProgram,
Transaction,
} from '@solana/web3.js';
import * as base58 from 'bs58';
(async () => {
const commitment: Commitment = 'processed';
const connection = new Connection('https://api.testnet.v1.sonic.game', {
commitment,
wsEndpoint: 'wss://api.testnet.v1.sonic.game'
});
const sender: Keypair = Keypair.fromSecretKey(base58.decode("4DcqYGxBW1WHHwUi7mRnN3uxPbG6oiXRTJ5Fq3nNg74DUs56Ht5JbKmnce7XAcPEt2si5Gyvd2GNLxCHrw1ckXFs"));
const tx = new Transaction();
tx.add(
SystemProgram.transfer({
fromPubkey: sender.publicKey,
toPubkey: new PublicKey("KjkadiKKYic9Qs53qXScUJDSM6KoG9BnBG4s8iNkP6f"),
lamports: 0.01 * LAMPORTS_PER_SOL
})
);
tx.feePayer = sender.publicKey;
tx.recentBlockhash = (await connection.getLatestBlockhash())[0];
const txHash = await connection.sendTransaction(tx, [sender]);
console.log("tx hash: ", txHash);
})();