-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3.1.transaction-sol-raw.ts
52 lines (41 loc) · 1.59 KB
/
3.1.transaction-sol-raw.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
import web3, { Connection } from "@solana/web3.js";
import base58 from "bs58";
const connection = new Connection(process.env.RPC);
const fromWallet = web3.Keypair.fromSecretKey(
base58.decode(process.env.PRIVATE_KEY),
);
console.log("from wallet", fromWallet.publicKey.toBase58());
// request airdop 1 sol to fromWallet
// try {
// let txhash = await connection.requestAirdrop(fromWallet.publicKey, 1e9);
// console.log(`airdrop txhash: ${txhash}`);
// } catch (err) {
// console.error(err);
// }
const toPublicKey = new web3.PublicKey(process.env.PUBLIC_KEY);
let oldBalance = await connection.getBalance(fromWallet.publicKey);
console.log("old balance", oldBalance);
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 1,
});
const transaction = new web3.Transaction().add(
web3.SystemProgram.transfer({
fromPubkey: fromWallet.publicKey,
toPubkey: toPublicKey,
lamports: 10 ** 9 * 0.003,
}),
);
transaction.sign(fromWallet);
const signature = await connection.sendRawTransaction(transaction.serialize());
console.log("signature", signature);
await connection.confirmTransaction(signature, "confirmed");
// let tx = await connection.getTransaction(signature);
// console.log("transaction", tx);
let newBalance = await connection.getBalance(fromWallet.publicKey);
console.log("new balance", newBalance);
await Bun.sleep(1000);
newBalance = await connection.getBalance(fromWallet.publicKey);
console.log("new balance", newBalance);
await Bun.sleep(1000);
newBalance = await connection.getBalance(fromWallet.publicKey);
console.log("new balance", newBalance);