### Build and Run Node.js Examples Source: https://kaspa.aspectron.org/docs/index Steps to build and run Node.js examples for the Kaspa project. This includes installing dependencies, initializing configuration, and running example scripts. Node.js examples often accept network and encoding arguments. ```bash cd wasm ./build-release cd examples npm install node init node nodejs/javascript/general/rpc.js ``` -------------------------------- ### Serve Web Examples Locally Source: https://kaspa.aspectron.org/docs/index Instructions for serving Kaspa web examples from a local web server. Requires the SDK to be served from the root directory due to relative path usage in examples. WASM32 cannot be loaded via the `file://` protocol. ```bash cargo install http-server http-server ``` -------------------------------- ### Kaspa API Documentation - Virtual Chain Information Source: https://kaspa.aspectron.org/docs/classes/Header Provides interfaces for querying the virtual chain of the Kaspa network starting from a specific block. This includes requests to get the virtual chain from a given block. ```APIDOC IGetVirtualChainFromBlockRequest: (Represents a request to retrieve the virtual chain from a specified block.) IGetVirtualChainFromBlockResponse: (Represents a response containing the virtual chain from a specified block.) ``` -------------------------------- ### Build Project Documentation Source: https://kaspa.aspectron.org/docs/index Instructions for generating project documentation using typedoc. This process requires a Rust environment and involves building the WASM32 SDK first, followed by generating documentation from it. The output is placed in the `docs/typedoc/` directory. ```bash npm install -g typedoc ./build-docs ``` -------------------------------- ### Kaspa Initialization and Configuration Source: https://kaspa.aspectron.org/docs/interfaces/IGetFeeEstimateExperimentalRequest Functions for initializing the Kaspa environment, including setting up panic hooks, logging levels, and default storage paths. ```typescript // Initializes a panic hook for browser environments function initBrowserPanicHook(): void; // Initializes a panic hook for console environments function initConsolePanicHook(): void; // Initializes the synchronous Kaspa environment function initSync(initInput: InitInput): void; // Initializes WASM32 bindings for Kaspa function initWASM32Bindings(): void; // Sets the default storage folder for Kaspa data function setDefaultStorageFolder(folderPath: string): void; // Sets the default wallet file for Kaspa function setDefaultWalletFile(filePath: string): void; // Sets the logging level for Kaspa operations function setLogLevel(level: string): void; ``` -------------------------------- ### Derivation Path Operations Source: https://kaspa.aspectron.org/docs/interfaces/InitOutput Functions for manipulating derivation paths, including checking emptiness, getting length, creating new paths, getting parent paths, pushing elements, and converting to string. ```APIDOC derivationpath_isEmpty(path: DerivationPath): boolean Checks if the derivation path is empty. derivationpath_length(path: DerivationPath): number Returns the length of the derivation path. derivationpath_new(): DerivationPath Creates a new, empty derivation path. derivationpath_parent(path: DerivationPath): DerivationPath Returns the parent derivation path. derivationpath_push(path: DerivationPath, element: number): void Pushes an element onto the derivation path. derivationpath_toString(path: DerivationPath): string Converts the derivation path to its string representation. ``` -------------------------------- ### Kaspa Aspectron Wallet API Reference Source: https://kaspa.aspectron.org/docs/interfaces/InitOutput This section provides a comprehensive reference for the Kaspa Aspectron wallet API. It details various methods for managing wallets, accounts, transactions, and interacting with the Kaspa network. Each entry includes method signatures, parameter descriptions, return values, and usage examples where applicable. ```APIDOC Wallet Account Management: wallet_accountsPskbBroadcast(pskb: PSKB): Promise Broadcasts a partially signed transaction. Parameters: pskb: The partially signed transaction. Returns: The transaction ID. wallet_accountsPskbSend(pskb: PSKB): Promise Sends a partially signed transaction. Parameters: pskb: The partially signed transaction. Returns: The transaction ID. wallet_accountsPskbSign(pskb: PSKB): Promise Signs a partially signed transaction. Parameters: pskb: The partially signed transaction. Returns: The signed transaction. wallet_accountsRename(account: Account, newName: string): Promise Renames an existing account. Parameters: account: The account to rename. newName: The new name for the account. wallet_accountsSend(account: Account, to: Address, amount: BigNumber, fee?: BigNumber): Promise Sends funds from an account. Parameters: account: The account to send from. to: The recipient address. amount: The amount to send. fee: Optional fee amount. Returns: The transaction ID. wallet_accountsTransfer(from: Account, to: Account, amount: BigNumber, fee?: BigNumber): Promise Transfers funds between accounts. Parameters: from: The source account. to: The destination account. amount: The amount to transfer. fee: Optional fee amount. Returns: The transaction ID. Wallet Event Handling: wallet_addEventListener(event: WalletEvent, handler: Function): Promise Adds an event listener. Parameters: event: The type of event to listen for. handler: The function to call when the event occurs. wallet_removeEventListener(event: WalletEvent, handler: Function): Promise Removes an event listener. Parameters: event: The type of event to remove. handler: The handler function to remove. Wallet Address Book: wallet_addressBookEnumerate(): Promise Enumerates entries in the address book. Returns: An array of address book entries. Wallet Batch Operations: wallet_batch(operations: WalletOperation[]): Promise Executes a batch of wallet operations. Parameters: operations: An array of wallet operations. Returns: An array of results from the operations. Wallet Connection Management: wallet_connect(): Promise Connects to the wallet. wallet_disconnect(): Promise Disconnects from the wallet. wallet_isOpen(): Promise Checks if the wallet is open. Wallet Constructor and Initialization: wallet_constructor(): Promise Initializes the wallet constructor. wallet_descriptor(): Promise Gets the wallet descriptor. wallet_exists(walletName: string): Promise Checks if a wallet exists. Wallet Fee Rate Management: wallet_feeRateEstimate(): Promise Estimates the fee rate. wallet_feeRatePollerDisable(): Promise Disables the fee rate poller. wallet_feeRatePollerEnable(): Promise Enables the fee rate poller. Wallet Flushing: wallet_flush(): Promise Flushes the wallet data. Wallet Status and Synchronization: wallet_getStatus(): Promise Gets the current wallet status. wallet_isSynced(): Promise Checks if the wallet is synchronized. Wallet Private Key Management: wallet_prvKeyDataCreate(data: PrvKeyData): Creates new private key data. Parameters: data: The private key data to create. wallet_prvKeyDataEnumerate(): Promise Enumerates existing private key data. Returns: An array of private key data. wallet_prvKeyDataGet(id: string): Promise Retrieves private key data by ID. Parameters: id: The ID of the private key data. Returns: The private key data. wallet_prvKeyDataRemove(id: string): Promise Removes private key data by ID. Parameters: id: The ID of the private key data to remove. Wallet RPC Communication: wallet_rpc(request: RpcRequest): Promise Sends an RPC request to the wallet. Parameters: request: The RPC request object. Returns: The RPC response object. Wallet Network Configuration: wallet_setNetworkId(networkId: NetworkId): Promise Sets the network ID for the wallet. Parameters: networkId: The network ID to set. Wallet Start and Stop: wallet_start(): Promise Starts the wallet service. wallet_stop(): Promise Stops the wallet service. Wallet Transaction Data Management: wallet_transactionsDataGet(transactionId: string): Promise Retrieves data for a specific transaction. Parameters: transactionId: The ID of the transaction. Returns: The transaction data. wallet_transactionsReplaceMetadata(transactionId: string, metadata: object): Promise Replaces metadata for a transaction. Parameters: transactionId: The ID of the transaction. metadata: The new metadata. wallet_transactionsReplaceNote(transactionId: string, note: string): Promise Replaces the note for a transaction. Parameters: transactionId: The ID of the transaction. note: The new note. Wallet Wallet Management: wallet_walletChangeSecret(walletName: string, newSecret: string): Promise Changes the secret for a wallet. Parameters: walletName: The name of the wallet. newSecret: The new secret. wallet_walletClose(walletName: string): Promise Closes a wallet. Parameters: walletName: The name of the wallet to close. wallet_walletCreate(walletName: string, secret: string): Promise Creates a new wallet. Parameters: walletName: The name of the wallet to create. secret: The secret for the new wallet. wallet_walletEnumerate(): Promise Enumerates all available wallets. Returns: An array of wallet information. wallet_walletExport(walletName: string): Promise Exports a wallet. Parameters: walletName: The name of the wallet to export. Returns: The exported wallet data. wallet_walletImport(walletName: string, walletData: string): Promise Imports a wallet. Parameters: walletName: The name of the wallet to import. walletData: The data of the wallet to import. wallet_walletOpen(walletName: string, secret: string): Promise Opens a wallet. Parameters: walletName: The name of the wallet to open. secret: The secret for the wallet. wallet_walletReload(walletName: string): Promise Reloads a wallet. Parameters: walletName: The name of the wallet to reload. WASIOptions: wasioptions_args(args: string[]): Promise Sets WASI arguments. Parameters: args: An array of arguments. Returns: WASIOptions object. wasioptions_env(env: { [key: string]: string }): Promise Sets WASI environment variables. Parameters: env: An object of environment variables. Returns: WASIOptions object. wasioptions_new(): Promise Creates new WASIOptions. Returns: WASIOptions object. ``` -------------------------------- ### Derivation Path Operations Source: https://kaspa.aspectron.org/docs/interfaces/InitOutput Functions for manipulating derivation paths, including checking emptiness, getting length, creating new paths, getting parent paths, pushing elements, and converting to string. ```APIDOC derivationpath_isEmpty(): boolean Checks if the derivation path is empty. derivationpath_length(): number Gets the length of the derivation path. derivationpath_new(): object Creates a new derivation path. derivationpath_parent(): object Gets the parent derivation path. derivationpath_push(element: string | number) Pushes an element onto the derivation path. derivationpath_toString(): string Converts the derivation path to a string. ``` -------------------------------- ### Kaspa Initialization and Utility Functions Source: https://kaspa.aspectron.org/docs/interfaces/InitOutput Contains functions for initializing panic hooks in different environments (browser, console) and initializing WASM32 bindings. Also includes utility functions for script type checking and currency conversion. ```APIDOC initBrowserPanicHook: () => void initConsolePanicHook: () => void initWASM32Bindings: (a, b) => void isScriptPayToPubkey: (a, b) => void isScriptPayToPubkeyECDSA: (a, b) => void isScriptPayToScriptHash: (a, b) => void kaspaToSompi: (a, b) => number ``` -------------------------------- ### Kaspa Initialization and Utility Functions Source: https://kaspa.aspectron.org/docs/interfaces/InitOutput Contains functions for initializing the WASM environment, setting up panic hooks, and retrieving network parameters. ```APIDOC defer(callback: () => void): void // Schedules a function to be called later, similar to defer in other languages. // Parameters: // callback: The function to defer. getNetworkParams(networkId: string): any // Retrieves the network parameters for a given Kaspa network ID. // Parameters: // networkId: The Kaspa network identifier (e.g., 'mainnet', 'testnet'). // Returns: An object containing network parameters. initBrowserPanicHook(): void // Initializes a panic hook for browser environments. initConsolePanicHook(): void // Initializes a panic hook for console (Node.js) environments. initSync(config: any): Promise // Initializes the synchronous components of the Kaspa Aspectron library. // Parameters: // config: Configuration object for initialization. initWASM32Bindings(): void // Initializes the WASM32 bindings for the library. ``` -------------------------------- ### Kaspa API: Type Declaration Example Source: https://kaspa.aspectron.org/docs/interfaces/InitOutput An example of a type declaration in Kaspa's API, specifying a function that returns a number. This is a basic type definition found in the project's TypeScript definition files. ```APIDOC (): number Returns: number Defined in web/kaspa/kaspa.d.ts:8458 ``` -------------------------------- ### Kaspa RPC and Wallet Initialization Source: https://kaspa.aspectron.org/docs/interfaces/IGetInfoResponse API documentation for initializing RPC connections and wallet functionalities. This includes methods for setting up WebSocket configurations and handling wallet events. ```APIDOC APIDOC: Kaspa RPC and Wallet Initialization: initSync(config: IWebSocketConfig): Promise Initializes a synchronized connection to the Kaspa network via WebSocket. Parameters: config: An object conforming to IWebSocketConfig, specifying connection details. Returns: A Promise that resolves with the initialized connection object or rejects on error. initBrowserPanicHook(): void Initializes a panic hook for browser environments to catch and report panics. initConsolePanicHook(): void Initializes a panic hook for console environments to catch and report panics. initWASM32Bindings(): void Initializes WASM32 bindings for the Kaspa library. Related Interfaces: IWebSocketConfig: Configuration for WebSocket connections. IWalletOpenResponse: Response structure for opening a wallet. IWalletReloadEvent: Event data for wallet reloads. IWalletReloadRequest: Request structure for reloading a wallet. IWalletReloadResponse: Response structure for wallet reload requests. IWalletEvent: Base interface for wallet-related events. WalletEventMap: Maps event names to their corresponding callback types. WalletNotificationCallback: Callback function type for wallet notifications. ``` -------------------------------- ### Transaction Maturity Function Source: https://kaspa.aspectron.org/docs/classes/PublicKeyGenerator A function to get the maturity progress of a Kaspa transaction. ```typescript /** * Gets the maturity progress of a transaction. * @param transactionId - The ID of the transaction. * @returns A promise that resolves with the maturity progress information. */ getTransactionMaturityProgress(transactionId: string): Promise; ``` -------------------------------- ### Kaspa WebSocket and Initialization Interfaces Source: https://kaspa.aspectron.org/docs/functions/initSync Covers interfaces for WebSocket configuration and the output of an initialization process, essential for network communication and setting up the Kaspa environment. ```APIDOC IWebSocketConfig: Configuration for WebSocket connections. InitOutput: Output structure from an initialization process. ``` -------------------------------- ### Get Public Key Fingerprint Source: https://kaspa.aspectron.org/docs/classes/PublicKey Shows how to compute the 4-byte fingerprint of a PublicKey. ```typescript import { PublicKey } from "@aspectron/kaspa-wasm"; const publicKeyHex = "02f8a3f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7f7a7"; const publicKey = new PublicKey(publicKeyHex); const fingerprint = publicKey.fingerprint(); console.log(`Public Key Fingerprint: ${fingerprint}`); ``` -------------------------------- ### Kaspa API: Get Headers Source: https://kaspa.aspectron.org/docs/classes/UtxoContext Defines the request and response structures for retrieving block headers. ```APIDOC IGetHeadersRequest: blockHashes: string[] IGetHeadersResponse: headers: IHeader[] ``` -------------------------------- ### Kaspa WebSocket and Initialization Interfaces Source: https://kaspa.aspectron.org/docs/interfaces/IGetCoinSupplyRequest Covers interfaces for WebSocket configuration and the output of an initialization process, essential for network communication and setting up the Kaspa environment. ```APIDOC IWebSocketConfig: Configuration for WebSocket connections. InitOutput: Output structure from an initialization process. ``` -------------------------------- ### Kaspa WebSocket and Initialization Interfaces Source: https://kaspa.aspectron.org/docs/interfaces/IGetFeeEstimateExperimentalRequest Covers interfaces for WebSocket configuration and the output of an initialization process, essential for network communication and setting up the Kaspa environment. ```APIDOC IWebSocketConfig: Configuration for WebSocket connections. InitOutput: Output structure from an initialization process. ``` -------------------------------- ### Kaspa API: Get Headers Source: https://kaspa.aspectron.org/docs/interfaces/IHeader Defines the request and response structures for retrieving block headers. ```APIDOC IGetHeadersRequest: blockHashes: string[] IGetHeadersResponse: headers: IHeader[] ``` -------------------------------- ### Kaspa WebSocket and Initialization Interfaces Source: https://kaspa.aspectron.org/docs/types/SyncInitInput Covers interfaces for WebSocket configuration and the output of an initialization process, essential for network communication and setting up the Kaspa environment. ```APIDOC IWebSocketConfig: Configuration for WebSocket connections. InitOutput: Output structure from an initialization process. ``` -------------------------------- ### Kaspa API: Get Connections Source: https://kaspa.aspectron.org/docs/classes/UtxoContext Defines the request and response structures for obtaining information about network connections. ```APIDOC IGetConnectionsResponse: isBanned(peerId: string): boolean isKnown(peerId: string): boolean isTrusted(peerId: string): boolean isBannedOrKnown(peerId: string): boolean isBannedOrTrusted(peerId: string): boolean isKnownOrTrusted(peerId: string): boolean isBannedOrKnownOrTrusted(peerId: string): boolean getPeer(peerId: string): Peer | undefined getBannedPeers(): Peer[] getKnownPeers(): Peer[] getTrustedPeers(): Peer[] getBannedOrKnownPeers(): Peer[] getBannedOrTrustedPeers(): Peer[] getKnownOrTrustedPeers(): Peer[] getBannedOrKnownOrTrustedPeers(): Peer[] getPeers(): Peer[] Peer: id: string addr: string lastContact: number tried: boolean banned: boolean bannedUntil: number lastSent: number lastRecv: number network: string version: string protocol: string inbound: boolean outbound: boolean known: boolean trusted: boolean ``` -------------------------------- ### Kaspa WASM32 SDK API Reference Source: https://kaspa.aspectron.org/docs/functions/initSync API documentation for the Kaspa WASM32 SDK, covering function signatures, parameters, return types, and member visibility. ```APIDOC Function initSync: Signature: initSync(module): InitOutput Description: Instantiates the given `module`, which can either be bytes or a precompiled `WebAssembly.Module`. Parameters: * module: SyncInitInput | { module: SyncInitInput } (Passing `SyncInitInput` directly is deprecated.) Returns: InitOutput Defined in: web/kaspa/kaspa.d.ts:8565 Member Visibility: * Protected * Private * Inherited * External ``` -------------------------------- ### Kaspa API: Get Connections Source: https://kaspa.aspectron.org/docs/interfaces/IHeader Defines the request and response structures for obtaining information about network connections. ```APIDOC IGetConnectionsResponse: isBanned(peerId: string): boolean isKnown(peerId: string): boolean isTrusted(peerId: string): boolean isBannedOrKnown(peerId: string): boolean isBannedOrTrusted(peerId: string): boolean isKnownOrTrusted(peerId: string): boolean isBannedOrKnownOrTrusted(peerId: string): boolean getPeer(peerId: string): Peer | undefined getBannedPeers(): Peer[] getKnownPeers(): Peer[] getTrustedPeers(): Peer[] getBannedOrKnownPeers(): Peer[] getBannedOrTrustedPeers(): Peer[] getKnownOrTrustedPeers(): Peer[] getBannedOrKnownOrTrustedPeers(): Peer[] getPeers(): Peer[] Peer: id: string addr: string lastContact: number tried: boolean banned: boolean bannedUntil: number lastSent: number lastRecv: number network: string version: string protocol: string inbound: boolean outbound: boolean known: boolean trusted: boolean ``` -------------------------------- ### Kaspa Transaction Maturity Progress Function Source: https://kaspa.aspectron.org/docs/enums/UtxoProcessorEventType Provides a function to get the maturity progress of a Kaspa transaction. ```APIDOC getTransactionMaturityProgress(transactionId: TransactionId): MaturityProgress ``` -------------------------------- ### Building Kaspa WASM32 SDK from Source Source: https://kaspa.aspectron.org/docs/index Commands to build the WASM32 SDK from source, including release versions, web packages, and Node.js packages. Requires Rust environment and TypeDoc. ```bash # Build the release version of the WASM32 SDK + Docs ./build-release # Build the web package (ES6 module) ./build-web # Build the NodeJS package (CommonJS module) ./build-node # Build the web package and generate TypeDoc documentation ./build-docs ``` -------------------------------- ### Kaspa WebSocket and Initialization Interfaces Source: https://kaspa.aspectron.org/docs/functions/initWASM32Bindings Covers interfaces for WebSocket configuration and the output of an initialization process, essential for network communication and setting up the Kaspa environment. ```APIDOC IWebSocketConfig: Configuration for WebSocket connections. InitOutput: Output structure from an initialization process. ```