### Basic Setup with TypeScript Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=code Demonstrates the basic setup for using the @mayaprotocol/zcash-js library in TypeScript. It initializes the configuration object with Zcash node details and network selection (mainnet/testnet). ```typescript import { Config, buildTx, signAndFinalize, sendRawTransaction, getUTXOS } from '@mayaprotocol/zcash-js'; const config: Config = { server: { host: 'http://localhost:8232', // Your Zcash node URL user: 'your-rpc-user', password: 'your-rpc-password' }, mainnet: true // or false for testnet }; ``` -------------------------------- ### Installation Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Install the @mayaprotocol/zcash-js package using npm. ```APIDOC ## Installation ```bash npm install @mayaprotocol/zcash-js ``` ``` -------------------------------- ### Basic Setup and Configuration Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependents Configure the zcash-js library by defining connection details for your Zcash node and specifying whether to use mainnet or testnet. This setup is crucial for all subsequent interactions with the Zcash network. ```typescript import { Config } from '@mayaprotocol/zcash-js'; const config: Config = { server: { host: 'http://localhost:8232', // Your Zcash node URL user: 'your-rpc-user', password: 'your-rpc-password' }, mainnet: true // or false for testnet }; ``` -------------------------------- ### Basic Usage Example Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Demonstrates how to set up the configuration for interacting with a Zcash node. ```APIDOC ## Usage ### Basic Setup ```typescript import { Config } from '@mayaprotocol/zcash-js'; const config: Config = { server: { host: 'http://localhost:8232', // Your Zcash node URL user: 'your-rpc-user', password: 'your-rpc-password' }, mainnet: true // or false for testnet }; ``` ``` -------------------------------- ### Install @mayaprotocol/zcash-js Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=code Installs the @mayaprotocol/zcash-js package using npm. This package provides functionalities for interacting with Zcash nodes, primarily for Maya Protocol integration. ```bash npm install @mayaprotocol/zcash-js ``` -------------------------------- ### Building and Sending a Transaction Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Example of building, signing, and sending a Zcash transaction. ```APIDOC ### Building and Sending a Transaction ```typescript import { getUTXOS, buildTx, signAndFinalize, sendRawTransaction } from '@mayaprotocol/zcash-js'; // Get UTXOS for the source address const utxos = await getUTXOS('t1SourceAddress...', config); // Build the transaction const tx = await buildTx( 0, // current block height 't1SourceAddress...', // from address 't1DestinationAddress...', // to address 1000000, // amount in satoshis utxos, false // is this a memo transaction? ); // Sign the transaction const signedTx = await signAndFinalize( tx.height, 'your-private-key-hex', // private key for source address tx.inputs, tx.outputs ); // Send the transaction const txid = await sendRawTransaction(signedTx, config); console.log('Transaction ID:', txid); ``` ``` -------------------------------- ### Basic Zcash node configuration setup Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js Configure connection to a Zcash node with RPC credentials. Required for all subsequent operations. ```typescript import { Config } from '@mayaprotocol/zcash-js'; const config: Config = { server: { host: 'http://localhost:8232', user: 'your-rpc-user', password: 'your-rpc-password' }, mainnet: true }; ``` -------------------------------- ### Sending a Transaction with Memo Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Example of building a transaction that includes a memo field. ```APIDOC ### Sending a Transaction with Memo ```typescript const tx = await buildTx( 0, 't1SourceAddress...', 't1DestinationAddress...', 1000000, utxos, false, 'swap:cacao:maya1a7gg93dgwlulsrqf6qtage985ujhpu068zllw7' // memo text ); ``` ``` -------------------------------- ### Build, Sign, and Send Zcash Transaction Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=code Illustrates the process of building, signing, and sending a Zcash transaction using the @mayaprotocol/zcash-js library. This involves fetching UTXOs, constructing the transaction, signing it with a private key, and broadcasting it to the network. ```typescript // Get UTXOs for the source address const utxos = await getUTXOS('t1SourceAddress...', config); // Build the transaction const tx = await buildTx( 0, // current block height 't1SourceAddress...', // from address 't1DestinationAddress...', // to address 1000000, // amount in satoshis utxos, false // is this a memo transaction? ); // Sign the transaction const signedTx = await signAndFinalize( tx.height, 'your-private-key-hex', // private key for source address tx.inputs, tx.outputs ); // Send the transaction const txid = await sendRawTransaction(signedTx, config); console.log('Transaction ID:', txid); ``` -------------------------------- ### Build and Send Zcash Transaction (JavaScript/TypeScript) Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependencies Demonstrates building, signing, and sending a Zcash transaction using the library. It involves retrieving UTXOs, constructing the transaction, and utilizing the library's functions for signing and broadcasting the transaction. ```JavaScript/TypeScript import { Config, buildTx, signAndFinalize, sendRawTransaction, getUTXOS } from '@mayaprotocol/zcash-js'; const config: Config = { server: { host: 'http://localhost:8232', // Your Zcash node URL user: 'your-rpc-user', password: 'your-rpc-password' }, mainnet: true // or false for testnet }; // Get UTXOs for the source address const utxos = await getUTXOS('t1SourceAddress...', config); // Build the transaction const tx = await buildTx( 0, // current block height 't1SourceAddress...', // from address 't1DestinationAddress...', // to address 1000000, // amount in satoshis utxos, false // is this a memo transaction? ); // Sign the transaction const signedTx = await signAndFinalize( tx.height, 'your-private-key-hex', // private key for source address tx.inputs, tx.outputs ); // Send the transaction const txid = await sendRawTransaction(signedTx, config); console.log('Transaction ID:', txid); ``` -------------------------------- ### Build and send Zcash transaction Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js Complete workflow for creating, signing, and broadcasting a Zcash transaction. Requires UTXOs and private key. ```typescript const utxos = await getUTXOS('t1SourceAddress...', config); const tx = await buildTx( 0, 't1SourceAddress...', 't1DestinationAddress...', 1000000, utxos, false ); const signedTx = await signAndFinalize( tx.height, 'your-private-key-hex', tx.inputs, tx.outputs ); const txid = await sendRawTransaction(signedTx, config); console.log('Transaction ID:', txid); ``` -------------------------------- ### API Reference - Functions Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Reference for the functions available in the @mayaprotocol/zcash-js library. ```APIDOC ### Functions * `getUTXOS(address: string, config: Config): Promise` - Get unspent transaction outputs for an address * `buildTx(height: number, from: string, to: string, amount: number, utxos: UTXO[], extraFeeForMemo: boolean, memo?: string): Promise` - Build a transaction * `signAndFinalize(height: number, privateKey: string, inputs: Input[], outputs: Output[]): Promise` - Sign and finalize a transaction * `sendRawTransaction(txb: Buffer, config: Config): Promise` - Send a signed transaction * `pkToAddr(publicKey: Buffer, prefix: Buffer): string` - Generate address from public key * `isValidAddr(address: string, prefix: Buffer): boolean` - Validate an address * `waitForTransaction(txid: string, config: Config, maxAttempts?: number): Promise` - Wait for transaction confirmation ``` -------------------------------- ### Generate Zcash Address from Public Key Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=code Demonstrates how to generate a Zcash address from a given public key using the @mayaprotocol/zcash-js library. It specifies whether to use the mainnet or testnet prefix. ```typescript import { pkToAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Generate address from public key const publicKey = Buffer.from('02aa7ef4b1958837763303a675dea8f63eaf264494072f086acdbc78d0decb0d0f', 'hex'); const address = pkToAddr(publicKey, Buffer.from(testnetPrefix)); console.log('Address:', address); // tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW ``` -------------------------------- ### Generate Zcash Address from Public Key (JavaScript/TypeScript) Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependencies Demonstrates how to generate a Zcash address from a public key using the provided library functions. This includes specifying the appropriate network prefix (testnet or mainnet). ```JavaScript/TypeScript import { pkToAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Generate address from public key const publicKey = Buffer.from('02aa7ef4b1958837763303a675dea8f63eaf264494072f086acdbc78d0decb0d0f', 'hex'); const address = pkToAddr(publicKey, Buffer.from(testnetPrefix)); console.log('Address:', address); ``` -------------------------------- ### API Reference - Types Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme API reference for the Config and UTXO types used in the library. ```APIDOC ## API Reference ### Types #### Config ```typescript interface Config { server: { host: string; // Zcash RPC endpoint URL user: string; // RPC username password: string; // RPC password }; mainnet: boolean; // true for mainnet, false for testnet } ``` #### UTXO ```typescript interface UTXO { txid: string; vout: number; amount: number; scriptPubKey: { hex: string; addresses: string[]; }; confirmations: number; } ``` ``` -------------------------------- ### Config Interface Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Configuration interface for connecting to a Zcash node. ```APIDOC ## Config Interface ### Description Interface for configuring connection to a Zcash RPC node. ### Structure #### server - **host** (string) - Required - Zcash RPC endpoint URL - **user** (string) - Required - RPC username - **password** (string) - Required - RPC password #### mainnet - **mainnet** (boolean) - Required - true for mainnet, false for testnet ### Example ``` interface Config { server: { host: string; user: string; password: string; }; mainnet: boolean; } ``` ``` -------------------------------- ### buildTx Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Builds a Zcash transaction with optional memo support. ```APIDOC ## POST /buildTx ### Description Builds a Zcash transaction from provided parameters and UTXOs. ### Method POST ### Endpoint /buildTx ### Request Body - **height** (number) - Required - Current block height - **from** (string) - Required - Source address - **to** (string) - Required - Destination address - **amount** (number) - Required - Amount in satoshis - **utxos** (UTXO[]) - Required - Array of UTXO objects - **extraFeeForMemo** (boolean) - Required - Whether to add extra fee for memo - **memo** (string) - Optional - Memo text for the transaction ### Response #### Success Response (200) - **height** (number) - Current block height - **inputs** (Input[]) - Transaction inputs - **outputs** (Output[]) - Transaction outputs #### Response Example ``` { "height": 123456, "inputs": [...], "outputs": [...] } ``` ``` -------------------------------- ### Address Generation Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Generate a Zcash address from a public key. ```APIDOC ### Address Generation ```typescript import { pkToAddr, testnetPrefix } from '@mayaprotocol/zcash-js'; // Generate address from public key const publicKey = Buffer.from('02aa7ef4b1958837763303a675dea8f63eaf264494072f086acdbc78d0decb0d0f', 'hex'); const address = pkToAddr(publicKey, Buffer.from(testnetPrefix)); console.log('Address:', address); // tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW ``` ``` -------------------------------- ### pkToAddr Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Generates a Zcash address from a public key. ```APIDOC ## GET /pkToAddr ### Description Generates a Zcash address from a provided public key and network prefix. ### Method GET ### Endpoint /pkToAddr ### Parameters #### Query Parameters - **publicKey** (Buffer) - Required - Public key buffer - **prefix** (Buffer) - Required - Network prefix buffer (mainnet or testnet) ### Response #### Success Response (200) - **address** (string) - Generated Zcash address #### Response Example ``` "tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW" ``` ``` -------------------------------- ### Zcash configuration interface Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js TypeScript interface defining the structure for Zcash node configuration. ```typescript interface Config { server: { host: string; user: string; password: string; }; mainnet: boolean; } ``` -------------------------------- ### Generate Zcash address from public key Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js Convert a public key to a Zcash address with specified network prefix (mainnet or testnet). ```typescript import { pkToAddr, testnetPrefix } from '@mayaprotocol/zcash-js'; const publicKey = Buffer.from('02aa7ef4b1958837763303a675dea8f63eaf264494072f086acdbc78d0decb0d0f', 'hex'); const address = pkToAddr(publicKey, Buffer.from(testnetPrefix)); console.log('Address:', address); ``` -------------------------------- ### getUTXOS Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Retrieves unspent transaction outputs for a specified address. ```APIDOC ## GET /getUTXOS ### Description Retrieves unspent transaction outputs (UTXOs) for a specified Zcash address. ### Method GET ### Endpoint /getUTXOS ### Parameters #### Path Parameters None #### Query Parameters - **address** (string) - Required - Zcash address to retrieve UTXOs for #### Request Body - **config** (Config) - Required - Configuration object for connecting to Zcash node ### Response #### Success Response (200) - **[]** (UTXO[]) - Array of UTXO objects #### Response Example ``` [ { "txid": "abcd1234", "vout": 1, "amount": 1000000, "scriptPubKey": { "hex": "76a914abc123...", "addresses": ["t1SourceAddress..."] }, "confirmations": 6 } ] ``` ``` -------------------------------- ### Create Zcash transaction with memo Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js Build a transaction containing a memo field for additional data. Useful for protocol-specific messages. ```typescript const tx = await buildTx( 0, 't1SourceAddress...', 't1DestinationAddress...', 1000000, utxos, false, 'swap:cacao:maya1a7gg93dgwlulsrqf6qtage985ujhpu068zllw7' ); ``` -------------------------------- ### Send Zcash Transaction with Memo Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Build and send a Zcash transaction with an attached memo field. Useful for adding additional information to transactions. ```typescript const tx = await buildTx( 0, 't1SourceAddress...', 't1DestinationAddress...', 1000000, utxos, false, 'swap:cacao:maya1a7gg93dgwlulsrqf6qtage985ujhpu068zllw7' // memo text ); ``` -------------------------------- ### Config Interface Definition (JavaScript/TypeScript) Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependencies Defines the structure of the Config object used for configuring the Zcash node connection. ```JavaScript/TypeScript interface Config { server: { host: string; // Zcash RPC endpoint URL user: string; // RPC username password: string; // RPC password }; mainnet: boolean; // true for mainnet, false for testnet } ``` -------------------------------- ### UTXO Interface Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Interface representing an unspent transaction output. ```APIDOC ## UTXO Interface ### Description Interface representing an unspent transaction output from a Zcash address. ### Structure - **txid** (string) - Required - Transaction ID - **vout** (number) - Required - Output index - **amount** (number) - Required - Amount in satoshis - **scriptPubKey** (object) - Required - Script public key information - **hex** (string) - Required - Script in hexadecimal format - **addresses** (string[]) - Required - Associated addresses - **confirmations** (number) - Required - Number of confirmations ### Example ``` interface UTXO { txid: string; vout: number; amount: number; scriptPubKey: { hex: string; addresses: string[]; }; confirmations: number; } ``` ``` -------------------------------- ### signAndFinalize Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Signs and finalizes a Zcash transaction. ```APIDOC ## POST /signAndFinalize ### Description Signs and finalizes a Zcash transaction using the provided private key. ### Method POST ### Endpoint /signAndFinalize ### Request Body - **height** (number) - Required - Current block height - **privateKey** (string) - Required - Private key in hexadecimal format - **inputs** (Input[]) - Required - Transaction inputs - **outputs** (Output[]) - Required - Transaction outputs ### Response #### Success Response (200) - **txb** (Buffer) - Signed transaction buffer #### Response Example ``` ``` ``` -------------------------------- ### Generate Zcash Address from Public Key Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependents Create a Zcash address by deriving it from a given public key. This function requires the public key in hexadecimal format and the appropriate network prefix (mainnet or testnet). ```typescript import { pkToAddr, testnetPrefix } from '@mayaprotocol/zcash-js'; // Generate address from public key const publicKey = Buffer.from('02aa7ef4b1958837763303a675dea8f63eaf264494072f086acdbc78d0decb0d0f', 'hex'); const address = pkToAddr(publicKey, Buffer.from(testnetPrefix)); console.log('Address:', address); // tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW ``` -------------------------------- ### Address Generation and Validation Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/index Generate Zcash addresses from public keys and validate existing addresses using network-specific prefixes. Essential for Zcash address management and validation for both mainnet and testnet environments. ```typescript import { pkToAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Generate address from public key const publicKey = Buffer.from('02aa7ef4b1958837763303a675dea8f63eaf264494072f086acdbc78d0decb0d0f', 'hex'); const address = pkToAddr(publicKey, Buffer.from(testnetPrefix)); console.log('Address:', address); // tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW ``` ```typescript import { isValidAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Validate testnet address const isValid = isValidAddr('tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW', Buffer.from(testnetPrefix)); console.log('Is valid testnet address:', isValid); // true // Validate mainnet address const isMainnetValid = isValidAddr('t1R97mnhVqcE7Yq8p7yL4E29gy8etq9V9pG', Buffer.from(mainnetPrefix)); console.log('Is valid mainnet address:', isMainnetValid); // true ``` -------------------------------- ### Build Zcash Transaction with Memo Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependents Construct a Zcash transaction that includes a memo field. This is useful for adding additional information, such as payment details or swap information, to your transactions. The `memo` parameter should be a string. ```typescript const tx = await buildTx( 0, 't1SourceAddress...', // from address 't1DestinationAddress...', // to address 1000000, // amount in satoshis utxos, // previously fetched UTXOs false, // is this a memo transaction? 'swap:cacao:maya1a7gg93dgwlulsrqf6qtage985ujhpu068zllw7' // memo text ); ``` -------------------------------- ### Address Validation Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=readme Validate a Zcash address for mainnet or testnet. ```APIDOC ### Address Validation ```typescript import { isValidAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Validate testnet address const isValid = isValidAddr('tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW', Buffer.from(testnetPrefix)); console.log('Is valid testnet address:', isValid); // true // Validate mainnet address const isMainnetValid = isValidAddr('t1R97mnhVqcE7Yq8p7yL4E29gy8etq9V9pG', Buffer.from(mainnetPrefix)); console.log('Is valid mainnet address:', isMainnetValid); // true ``` ``` -------------------------------- ### Send Zcash Transaction with Memo (JavaScript/TypeScript) Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependencies This code snippet demonstrates how to include a memo field in a Zcash transaction when building and sending it using the library. ```JavaScript/TypeScript const tx = await buildTx( 0, 't1SourceAddress...', 't1DestinationAddress...', 1000000, utxos, false, 'swap:cacao:maya1a7gg93dgwlulsrqf6qtage985ujhpu068zllw7' // memo text ); ``` -------------------------------- ### Validate Zcash Address Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=code Explains how to validate a Zcash address using the @mayaprotocol/zcash-js library. It checks the validity against the specified network prefix (mainnet or testnet). ```typescript import { isValidAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Validate testnet address const isValid = isValidAddr('tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW', Buffer.from(testnetPrefix)); console.log('Is valid testnet address:', isValid); // true // Validate mainnet address const isMainnetValid = isValidAddr('t1R97mnhVqcE7Yq8p7yL4E29gy8etq9V9pG', Buffer.from(mainnetPrefix)); console.log('Is valid mainnet address:', isMainnetValid); // true ``` -------------------------------- ### isValidAddr Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Validates a Zcash address against a network prefix. ```APIDOC ## GET /isValidAddr ### Description Validates whether a Zcash address is valid for the specified network prefix. ### Method GET ### Endpoint /isValidAddr ### Parameters #### Query Parameters - **address** (string) - Required - Zcash address to validate - **prefix** (Buffer) - Required - Network prefix buffer (mainnet or testnet) ### Response #### Success Response (200) - **isValid** (boolean) - Whether the address is valid #### Response Example ``` true ``` ``` -------------------------------- ### Validate Zcash Address (JavaScript/TypeScript) Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=dependencies Shows how to validate a Zcash address against a specified network (mainnet or testnet) using the library's validation function. ```JavaScript/TypeScript import { isValidAddr, mainnetPrefix, testnetPrefix } from '@mayaprotocol/zcash-js'; // Validate testnet address const isValid = isValidAddr('tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW', Buffer.from(testnetPrefix)); console.log('Is valid testnet address:', isValid); // Validate mainnet address const isMainnetValid = isValidAddr('t1R97mnhVqcE7Yq8p7yL4E29gy8etq9V9pG', Buffer.from(mainnetPrefix)); console.log('Is valid mainnet address:', isMainnetValid); ``` -------------------------------- ### Zcash UTXO interface Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js TypeScript interface defining the structure of Unspent Transaction Outputs (UTXOs) in Zcash. ```typescript interface UTXO { txid: string; vout: number; amount: number; scriptPubKey: { hex: string; addresses: string[]; }; confirmations: number; } ``` -------------------------------- ### Send Zcash Transaction with Memo Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=code Shows how to build a Zcash transaction that includes a memo field using the @mayaprotocol/zcash-js library. This is useful for adding additional information or identifiers to a transaction. ```typescript const tx = await buildTx( 0, 't1SourceAddress...', // from address 't1DestinationAddress...', // to address 1000000, // amount in satoshis utxos, // previously fetched UTXOs false, // is this a memo transaction? 'swap:cacao:maya1a7gg93dglue985ujhpu068zllw7' // memo text ); ``` -------------------------------- ### sendRawTransaction Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Sends a signed Zcash transaction to the network. ```APIDOC ## POST /sendRawTransaction ### Description Sends a signed raw Zcash transaction to the network via the configured node. ### Method POST ### Endpoint /sendRawTransaction ### Request Body - **txb** (Buffer) - Required - Signed transaction buffer - **config** (Config) - Required - Configuration object for connecting to Zcash node ### Response #### Success Response (200) - **txid** (string) - Transaction ID of the broadcast transaction #### Response Example ``` "a1b2c3d4e5f6..." ``` ``` -------------------------------- ### waitForTransaction Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js_activetab=versions Waits for a Zcash transaction to be confirmed. ```APIDOC ## POST /waitForTransaction ### Description Waits for a Zcash transaction to be confirmed on the network. ### Method POST ### Endpoint /waitForTransaction ### Request Body - **txid** (string) - Required - Transaction ID to wait for - **config** (Config) - Required - Configuration object for connecting to Zcash node - **maxAttempts** (number) - Optional - Maximum number of attempts to check for confirmation ### Response #### Success Response (200) None (resolves when confirmed) #### Response Example ``` // Resolves when transaction is confirmed ``` ``` -------------------------------- ### TypeScript Type Definitions Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/index TypeScript interface definitions for library configuration, transaction inputs (UTXO), and RPC connection settings. Essential for type safety when using the library in TypeScript projects. ```typescript interface Config { server: { host: string; // Zcash RPC endpoint URL user: string; // RPC username password: string; // RPC password }; mainnet: boolean; // true for mainnet, false for testnet } interface UTXO { txid: string; vout: number; amount: number; scriptPubKey: { hex: string; addresses: string[]; }; confirmations: number; } ``` -------------------------------- ### Validate Zcash address Source: https://www.npmjs.com/package/@mayaprotocol/zcash-js/package/%40mayaprotocol/zcash-js Check if a given string is a valid Zcash address for the specified network (mainnet or testnet). ```typescript import { isValidAddr, testnetPrefix } from '@mayaprotocol/zcash-js'; const isValid = isValidAddr('tmUzzEDRjvE3QC8RBUFD7DTi5LLL4zAEvKW', Buffer.from(testnetPrefix)); console.log('Is valid testnet address:', isValid); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.