-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwallet_broadcast_example.mo
More file actions
61 lines (53 loc) · 2.1 KB
/
wallet_broadcast_example.mo
File metadata and controls
61 lines (53 loc) · 2.1 KB
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
53
54
55
56
57
58
59
60
61
// Example demonstrating the new broadcasting functionality
import Wallet "../src/wallet";
import Errors "../src/errors";
import Result "mo:base/Result";
// Example usage of the new broadcasting features
persistent actor WalletBroadcastExample {
// Initialize a mainnet wallet
transient let wallet = Wallet.createMainnetWallet("dfx_test_key");
// Example: Build and broadcast a transaction in one step
public func sendKaspa(
from_address: Text,
to_address: Text,
amount: Nat64
) : async Result.Result<Wallet.TransactionResult, Errors.KaspaError> {
await wallet.sendTransaction(
from_address,
to_address,
amount,
null, // Use default fee
null // Use default derivation path
)
};
// Example: Build transaction without broadcasting (for manual submission)
public func buildTransaction(
from_address: Text,
to_address: Text,
amount: Nat64
) : async Result.Result<{serialized_tx: Text; fee_paid: Nat64}, Errors.KaspaError> {
await wallet.buildTransaction(
from_address,
to_address,
amount,
null, // Use default fee
null // Use default derivation path
)
};
// Example: Broadcast a pre-built transaction
public func broadcastTransaction(serialized_tx: Text) : async Result.Result<Text, Errors.KaspaError> {
await wallet.broadcastSerializedTransaction(serialized_tx)
};
// Example: Check transaction status
public func checkTransactionStatus(tx_id: Text) : async Result.Result<{status: Text; confirmations: ?Nat}, Errors.KaspaError> {
await wallet.getTransactionStatus(tx_id)
};
// Example: Get wallet balance
public func getBalance(address: Text) : async Result.Result<Wallet.Balance, Errors.KaspaError> {
await wallet.getBalance(address)
};
// Example: Generate a new address
public func generateAddress() : async Result.Result<Wallet.AddressInfo, Errors.KaspaError> {
await wallet.generateAddress(null, null) // Use defaults
};
}