Verify Balance
The "Verify Balance" component allows users to verify a Stellar Wallet and the balance.
The component includes fields for displaying the XLM balance.
Features
- Verifys Stellar Wallet key pairs.
- Displays the wallet balance in XLM.
C#
Install the Pakana.Stellar.Components NuGet package via the NuGet Package Manager Console.
.Net8.0 or greater is required.
dotnet add package Pakana.Stellar.Components
ℹ️
StellarSDK Dependency will install automatically
NuGet Package Implementation
<pakana.stellar.components.Pages.VerifyBalance/>
C#
@page "/VerifyAndDisplayBalance"
<h1>Verify Stellar Key Pair & Check Balance</h1>
<label for="publicKeyverification">Public Key:</label>
<input type="text" id="publicKeyverification" placeholder="Enter public key" style="width:
300px;">
<br>
<br>
<label for="secretKeyverification">Secret Key:</label>
<input type="text" id="secretKeyverification" placeholder="Enter secret key" style="width:
300px;">
<br>
<br>
<button onclick="verifyAndCheckBalance()">
Verify Key Pair & Check
Balance
</button>
<div id="balanceResult" style="margin-top: 20px;"></div>
@code{
string publicKey { set; get; } = "";
string secretKey { set; get; } = "";
string balanceResult { set; get; } = "";
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/8.0.0/stellarsdk.min.js"></script>
<script src="your-path-file/verifyBalance.js"></script>
Javascript
We've provided simple HTML and JavaScript that can be used in your project as partial-components or be customized and integrated into your existing codebase.
Stellar CDN
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
Example
<script>
function verifyAndCheckBalance() {
const publicKey = document.getElementById('publicKey').value.trim();
const secretKey = document.getElementById('secretKey').value.trim();
if (!StellarSdk.StrKey.isValidEd25519PublicKey(publicKey)) {
displayBalanceResult('Invalid public key.');
return;
}
if (!StellarSdk.StrKey.isValidEd25519SecretSeed(secretKey)) {
displayBalanceResult('Invalid secret key.');
return;
}
const server = new StellarSdk.Horizon.Server('https://horizontestnet.stellar.org');
// Use the secret key to sign transactions
const keyPair = StellarSdk.Keypair.fromSecret(secretKey);
// Check account balance
server.loadAccount(publicKey)
.then(account => {
const balance = account.balances.find(balance =>
balance.asset_type === 'native');
if (balance) {
displayBalanceResult(`Account balance: ${balance.balance}`);
} else {
displayBalanceResult('Account has no balance.');
}
})
.catch(error => {
console.error('Error loading account:', error);
displayBalanceResult('Error loading account. Please check the
keys and try again.');
});
}
function displayBalanceResult(message) {
const balanceResultElement = document.getElementById('balanceResult');
balanceResultElement.textContent = message;
}
</script>
HTML
<body>
<h1>Verify Balance</h1>
<label for="publicKey">Public Key:</label>
<input type="text" id="publicKey" placeholder="Enter public key" style="width:
300px;">
<br>
<br>
<label for="secretKey">Secret Key:</label>
<input type="text" id="secretKey" placeholder="Enter secret key" style="width:
300px;">
<br>
<br>
<button onclick="verifyAndCheckBalance()">
Verify Key Pair & Check
Balance
</button>
<div id="balanceResult" style="margin-top: 20px;"></div>
</body>