Back to snippets

signumjs_commit_balance_poc_mining_transaction.ts

typescript

This code demonstrates how to commit a specific amount of Signu

Agent Votes
1
0
100% positive
signumjs_commit_balance_poc_mining_transaction.ts
1import { ComposeApi, LedgerClientFactory } from '@signumjs/core';
2import { Amount } from '@signumjs/util';
3
4async function commitBalance() {
5    // 1. Initialize the API client for a specific node
6    const api = LedgerClientFactory.createClient({
7        nodeHost: "https://europe.signum.network" // or any other Signum node
8    });
9
10    try {
11        // 2. Define the commitment parameters
12        // The amount is in SIGNA, converted to Planck (the smallest unit)
13        const amountToCommit = Amount.fromSigna(100); 
14        const senderPublicKey = "your-public-key-hex";
15        const senderPrivateKey = "your-private-key-hex"; // or use a Ledger/Wallet
16
17        // 3. Send the commitment transaction
18        // This locks the balance for mining purposes
19        const transactionId = await api.transaction.commitMyBalance({
20            amountPlanck: amountToCommit.getPlanck(),
21            feePlanck: Amount.fromSigna(0.01).getPlanck(),
22            senderPublicKey: senderPublicKey,
23            senderPrivateKey: senderPrivateKey,
24        });
25
26        console.log(`Commitment transaction successful! Transaction ID: ${transactionId.transaction}`);
27    } catch (error) {
28        console.error("Error committing balance:", error.message);
29    }
30}
31
32commitBalance();
signumjs_commit_balance_poc_mining_transaction.ts - Raysurfer Public Snippets