Zcash

This guide explains how to implement Zcash memo functionality for Maya Protocol transactions. Zcash uses transparent addresses and OP_RETURN outputs to include transaction memos, enabling cross-chain swaps and liquidity operations.

Overview

Maya Protocol uses memos to identify transaction intent (swap, add liquidity, withdraw). For Zcash, memos are implemented using OP_RETURN outputs with specific constraints:

  • Maximum memo size: 80 bytes (Zcash OP_RETURN limit)

  • Address support: Transparent addresses only (t1... format)

  • Fee structure: ZIP-317 compliant (base + marginal fees)

  • Output placement: OP_RETURN with 0 value

Technical Implementation

OP_RETURN Structure

The memo is embedded as an OP_RETURN script:

OP_RETURN <length> <memo_bytes>

Where:

  • OP_RETURN: Bitcoin opcode 0x6a

  • <length>: Memo length (1-80 bytes)

  • <memo_bytes>: UTF-8 encoded memo data

Transaction Structure

A typical Maya Protocol Zcash transaction includes:

  1. Input(s): UTXOs from sender

  2. Payment output: Amount to Maya vault address

  3. Memo output: OP_RETURN with 0 value (memo)

  4. Change output: Remaining funds back to sender (if any)

Fee Calculation (ZIP-317)

Where:

  • base_fee = 10,000 zatoshis

  • marginal_fee = 5,000 zatoshis

  • Memo outputs count toward output_count

Implementation Approaches

Approach 1: Using librustzcash (Rust)

Direct implementation using the core Zcash Rust library with the add_null_data_output function introduced in commit b26c998c.

Complete Rust Example

Cargo.toml:

src/main.rs:

Expected output:

Running the Rust Example

Approach 2: Using @mayaprotocol/zcash-js

For JavaScript/TypeScript developers who want direct control over transaction building, @mayaprotocol/zcash-js provides low-level bindings for Zcash operations.

Installation

Complete TypeScript Project Setup

To make this fully runnable, create the following files:

package.json:

tsconfig.json:

src/index.ts:

Quick Start

Expected Output

Approach 3: Using XChainJS

For developers who prefer a high-level abstraction, XChainJS provides the @xchainjs/xchain-zcash package with a simplified API that handles all the low-level details:

Installation

Complete Project Setup

package.json:

tsconfig.json:

src/index.ts:

Quick Start

Expected Output

Summary

This guide provides three comprehensive approaches for implementing Zcash memo functionality with Maya Protocol:

  1. Approach 1: librustzcash - Direct Rust implementation using the core Zcash library

  2. Approach 2: @mayaprotocol/zcash-js - Low-level TypeScript/JavaScript bindings for direct control

  3. Approach 3: XChainJS - High-level TypeScript/JavaScript interface with simplified API

All examples are designed to be copy-pasteable and runnable, with complete project setup including dependencies, configuration files, and expected outputs. Each approach handles the 80-byte OP_RETURN limit and ZIP-317 fee calculation requirements properly.

For production use, always test on testnet first and ensure proper private key management and error handling.

Additional Resources

Common Issues and Troubleshooting

1. Memo Length Validation

  1. Transaction rejection

    • Check fee calculation includes memo output

    • Verify UTXO selection provides sufficient funds

    • Ensure memo format matches Maya Protocol specification

Security Considerations

  1. Memo Visibility: All OP_RETURN data is publicly visible on the blockchain

  2. Private Keys: Never expose private keys in code or logs

  3. Address Validation: Always validate addresses before sending transactions

  4. Fee Verification: Confirm fees are reasonable before broadcasting

  5. Network Selection: Ensure correct network (mainnet/testnet) configuration

Conclusion

Integrating Zcash with Maya Protocol requires proper handling of OP_RETURN outputs for memo communication. Whether implementing from scratch, using librustzcash, or leveraging XChainJS, the key requirements remain:

  • Respect the 80-byte memo limit

  • Use transparent addresses only

  • Calculate fees according to ZIP-317

  • Follow Maya Protocol memo format specifications

  • Place memo in OP_RETURN output with zero value

Choose the implementation approach that best fits your technology stack and requirements:

  • Approach 1 (Rust/librustzcash): Best for performance-critical applications, native Zcash integration, or when building Rust applications

  • Approach 2 (@mayaprotocol/zcash-js): Perfect for TypeScript/JavaScript developers who need direct control over transaction building and signing

  • Approach 3 (XChainJS): Ideal for web applications, Node.js services, or rapid prototyping with a simplified API

Last updated

Was this helpful?