Skip to content

Commit fad10cf

Browse files
author
fun
committedJun 5, 2024
-
1 parent 6b8e2a9 commit fad10cf

5 files changed

+54
-3
lines changed
 

‎0.1.chain-block.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Connection } from "@solana/web3.js";
2+
3+
const connection = new Connection(process.env.RPC);
4+
5+
let res = await connection.getBlockHeight();
6+
console.log("block height res", res, new Date());
7+
8+
// let resBlock = await connection.getBlock(269332927, {
9+
// maxSupportedTransactionVersion: 0,
10+
// });
11+
// console.log("block res", resBlock);

‎1.3.wallet-balance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ console.log("sol balance", balance);
1212
const pubkey = new PublicKey(process.env.PUBLIC_KEY);
1313
await connection.requestAirdrop(pubkey, 1 * 10 ** 9);
1414
console.log("pubkey balance", await connection.getBalance(pubkey));
15-
console.log("pubkey account", await connection.getAccountInfo(pubkey));
15+
// console.log("pubkey account", await connection.getAccountInfo(pubkey));

‎2.4.token-all-balances.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
2+
import { Connection, PublicKey } from "@solana/web3.js";
3+
4+
const connection = new Connection("https://api.mainnet-beta.solana.com");
5+
6+
const pubkey = new PublicKey("J3y4VWneyFZEqvemxi7uUViPjkmXzsZ8r9d4YwgwHTFh");
7+
8+
let accounts = await connection.getTokenAccountsByOwner(pubkey, {
9+
programId: TOKEN_PROGRAM_ID,
10+
});
11+
12+
console.log("token accounts ", accounts);
13+
console.log("token accounts ", accounts.value[0].pubkey.toBase58());
14+
15+
let balance = await connection.getTokenAccountBalance(accounts.value[0].pubkey);
16+
console.log("token accounts balance", balance.value.uiAmount);

‎3.1.transaction-sol.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ console.log("from wallet", fromWallet.publicKey.toBase58());
1818

1919
const toPublicKey = new web3.PublicKey(process.env.PUBLIC_KEY);
2020

21+
let oldBalance = await connection.getBalance(fromWallet.publicKey);
22+
console.log("old balance", oldBalance);
23+
24+
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
25+
units: 1000000,
26+
});
27+
28+
const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
29+
microLamports: 1,
30+
});
31+
2132
const transaction = new web3.Transaction().add(
2233
web3.SystemProgram.transfer({
2334
fromPubkey: fromWallet.publicKey,
@@ -34,5 +45,17 @@ console.log("sim logs", logs);
3445
const signature = await connection.sendTransaction(transaction, [fromWallet]);
3546
console.log("signature", signature);
3647

37-
let tx = await connection.getTransaction(signature);
38-
console.log("transaction", tx);
48+
await connection.confirmTransaction(signature, "confirmed");
49+
// let tx = await connection.getTransaction(signature);
50+
// console.log("transaction", tx);
51+
52+
let newBalance = await connection.getBalance(fromWallet.publicKey);
53+
console.log("new balance", newBalance);
54+
55+
await Bun.sleep(1000);
56+
newBalance = await connection.getBalance(fromWallet.publicKey);
57+
console.log("new balance", newBalance);
58+
59+
await Bun.sleep(1000);
60+
newBalance = await connection.getBalance(fromWallet.publicKey);
61+
console.log("new balance", newBalance);

‎env

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
PRIVATE_KEY=
22
PUBLIC_KEY=92U3aM8kRqihutqFWNDGxmWXxMHDrnAyFEMYXcKmvKcD
33
RPC=https://api.devnet.solana.com
4+
#RPC=https://api.mainnet-beta.solana.com

0 commit comments

Comments
 (0)
Please sign in to comment.