-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e901f71
commit c6cbf03
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js"; | ||
|
||
const publicKeyString = "GghvcjRjgFUzkzd7kq45cdmCjxKGaobdetiY99hG4crM"; // Example address | ||
|
||
// Check if the public key is valid | ||
try { | ||
const publicKey = new PublicKey("GgJJRwLg9NzFQ97o1CJLGLp1KLSUMBwFc6eQNVEr4fbW"); | ||
if (!publicKey.toString()) { | ||
throw new Error("Invalid public key format"); | ||
} | ||
|
||
//const connection = new Connection("https://api.devnet.solana.com", "confirmed"); | ||
|
||
|
||
// Connect to the Solana mainnet | ||
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed"); | ||
|
||
// Fetch balance in lamports (smallest unit of SOL) | ||
const balanceInLamports = await connection.getBalance(publicKey); | ||
|
||
// Convert lamports to SOL | ||
const balanceInSOL = balanceInLamports / LAMPORTS_PER_SOL; | ||
|
||
console.log(`💰 Finished! The balance for the wallet at address ${publicKey} is ${balanceInSOL} SOL.`); | ||
} catch (error) { | ||
console.error("Error:", error.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js"; | ||
|
||
const publicKey = new PublicKey("GghvcjRjgFUzkzd7kq45cdmCjxKGaobdetiY99hG4crM"); | ||
|
||
const connection = new Connection("https://api.devnet.solana.com", "confirmed"); | ||
|
||
const balanceInLamports = await connection.getBalance(publicKey); | ||
|
||
const balanceInSOL = balanceInLamports / LAMPORTS_PER_SOL; | ||
|
||
console.log( | ||
`💰 Finished! The balance for the wallet at address ${publicKey} is ${balanceInSOL}!`, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
Connection, | ||
PublicKey, | ||
clusterApiUrl, | ||
LAMPORTS_PER_SOL, | ||
} from "@solana/web3.js"; | ||
|
||
const connection = new Connection(clusterApiUrl("devnet")); | ||
const address = new PublicKey("CenYq6bDRB7p73EjsPEpiYN7uveyPUTdXkDkgUduboaN"); | ||
const balance = await connection.getBalance(address); | ||
const balanceInSol = balance / LAMPORTS_PER_SOL; | ||
|
||
console.log(`The balance of the account at ${address} is ${balanceInSol} SOL`); | ||
console.log(`✅ Finished!`); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters