ZK Compression
  • Introduction
    • Overview
    • Intro to Development
  • Event
    • 🗓️Event: 1000x Hackathon
  • Release Notes
    • JS - v0.21.0
  • Learn
    • In a Nutshell
    • Core Concepts
      • Compressed Account Model
      • State Trees
      • Validity Proofs
      • Lifecycle of a Transaction
      • Limitations
  • Developers
    • TypeScript Client
    • JSON RPC Methods
      • getCompressedAccount
      • getCompressedBalance
      • getCompressedTokenAccountBalance
      • getCompressedBalanceByOwner
      • getCompressedMintTokenHolders
      • getCompressedTokenBalancesByOwnerV2
      • getCompressedAccountsByOwner
      • getMultipleCompressedAccounts
      • getCompressedTokenAccountsByOwner
      • getCompressedTokenAccountsByDelegate
      • getTransactionWithCompressionInfo
      • getCompressedAccountProof
      • getMultipleCompressedAccountProofs
      • getMultipleNewAddressProofs
      • getValidityProof
      • getCompressionSignaturesForAccount
      • getCompressionSignaturesForAddress
      • getCompressionSignaturesForOwner
      • getCompressionSignaturesForTokenOwner
      • getLatestCompressionSignatures
      • getLatestNonVotingSignatures
      • getIndexerSlot
      • getIndexerHealth
    • Addresses and URLs
    • Creating Airdrops with Compressed Tokens
    • Using Token-2022
    • Add Compressed Token Support to Your Wallet
    • Create programs with the program-template
  • Node Operators
    • Run a Node
  • resources
    • Security
    • Privacy Policy
Powered by GitBook
On this page
  • What You'll Need to Get Started
  • A Quick Intro to Client-side Development
  • Quickstart
  • On-chain Program Development
  • Build by Example
  • Developer Environments
  • Getting Support
  • Next Steps

Was this helpful?

  1. Introduction

Intro to Development

Welcome! This guide has everything you need to know to start developing with ZK Compression on Solana.

PreviousOverviewNextEvent: 1000x Hackathon

Last updated 4 months ago

Was this helpful?

For the sake of brevity, this guide assumes you are familiar with the basics of Solana. If you aren't, we recommend reading the following:

What You'll Need to Get Started

Development with ZK Compression on Solana consists of two main parts:

The is the glue between clients and on-chain programs. It extends Solana's with additional endpoints for interacting with ZK compressed accounts. You can view the complete list of supported endpoints .

A Quick Intro to Client-side Development

The following TypeScript and Rust SDKs are used to interact with ZK Compression:

Language
SDK
Description

TypeScript

SDK to interact with compression programs via the ZK Compression RPC API

TypeScript

SDK to interact with the compressed token program

Rust

Rust client

RPC Connection

You need an RPC connection to interact with the network. You can either work with an RPC infrastructure provider that supports ZK Compression or run your own RPC Node.

supports ZK Compression and maintains its canonical RPC and .

Our local dev tooling supports Photon out of the box via the light test-validator command. To learn how to run a standalone Photon RPC node, visit the section.

Quickstart

The code samples work! You can copy & paste them into your IDE and run!

Installation (Node.js, Web)

npm install -g @lightprotocol/zk-compression-cli && \
npm install --save \
    @lightprotocol/stateless.js \
    @lightprotocol/compressed-token \
    @solana/web3.js
yarn global add @lightprotocol/zk-compression-cli && \
yarn add \
    @lightprotocol/stateless.js \
    @lightprotocol/compressed-token \
    @solana/web3.js
pnpm add -g @lightprotocol/zk-compression-cli && \
pnpm add \
    @lightprotocol/stateless.js \
    @lightprotocol/compressed-token \
    @solana/web3.js

Creating an RPC Connection

import {
  Rpc,
  createRpc,
} from "@lightprotocol/stateless.js";

// Helius exposes Solana and Photon RPC endpoints through a single URL
const RPC_ENDPOINT = "https://devnet.helius-rpc.com?api-key=<api_key>";
const PHOTON_ENDPOINT = RPC_ENDPOINT;
const PROVER_ENDPOINT = RPC_ENDPOINT;
const connection: Rpc = createRpc(RPC_ENDPOINT, PHOTON_ENDPOINT, PROVER_ENDPOINT)

console.log("connection", connection);

Using Localnet

# Start a local test validator
light test-validator
const stateless = require("@lightprotocol/stateless.js");

const connection = stateless.createRpc();

async function main() {
  let slot = await connection.getSlot();
  console.log(slot);

  let health = await connection.getIndexerHealth(slot);
  console.log(health);
  // "Ok"
}

main();

Minting and Transferring Compressed Tokens

This example uses the compressed token program, which is built using ZK Compression and offers an SPL-compatible token layout.

import {
  LightSystemProgram,
  Rpc,
  confirmTx,
  createRpc,
} from "@lightprotocol/stateless.js";
import { createMint, mintTo, transfer } from "@lightprotocol/compressed-token";
import { Keypair } from "@solana/web3.js";

const payer = Keypair.generate();
const tokenRecipient = Keypair.generate();

/// Helius exposes Solana and compression RPC endpoints through a single URL
const RPC_ENDPOINT = "https://devnet.helius-rpc.com?api-key=<api_key>";
const COMPRESSION_ENDPOINT = RPC_ENDPOINT;
const PROVER_ENDPOINT = RPC_ENDPOINT;
const connection: Rpc = createRpc(RPC_ENDPOINT, COMPRESSION_ENDPOINT, PROVER_ENDPOINT)

const main = async () => {
  /// Airdrop lamports to pay fees
  await confirmTx(
    connection,
    await connection.requestAirdrop(payer.publicKey, 10e9)
  );

  await confirmTx(
    connection,
    await connection.requestAirdrop(tokenRecipient.publicKey, 1e6)
  );

  /// Create compressed token mint
  const { mint, transactionSignature } = await createMint(
    connection,
    payer,
    payer.publicKey,
    9 // Number of decimals
  );

  console.log(`create-mint  success! txId: ${transactionSignature}`);

  /// Mint compressed tokens to the payer's account
  const mintToTxId = await mintTo(
    connection,
    payer,
    mint,
    payer.publicKey, // Destination
    payer,
    1e9 // Amount
  );

  console.log(`Minted 1e9 tokens to ${payer.publicKey} was a success!`);
  console.log(`txId: ${mintToTxId}`);

  /// Transfer compressed tokens from payer to tokenRecipient's pubkey
  const transferTxId = await transfer(
    connection,
    payer,
    mint,
    7e8, // Amount
    payer, // Owner
    tokenRecipient.publicKey // To address
  );

  console.log(`Transfer of 7e8 ${mint} to ${tokenRecipient.publicKey} was a success!`);
  console.log(`txId: ${transferTxId}`);
};

main();

On-chain Program Development

You can write custom programs using ZK compression in Anchor or native Rust.

Program
Description

The system program. It enforces the compressed account layout with ownership and sum checks and verifies the validity of your input state

It is also invoked to create/write to compressed accounts and PDAs

A compressed token implementation built on top of ZK Compression. It enforces a SPL-compatible token layout and allows for arbitrary compression/decompression between this and the SPL standard

Implements state and address trees. It is used by the Light System program

Build by Example

While you get started building with ZK Compression, use these GitHub resources available to help accelerate your journey:

Developer Environments

ZK Compression is available on Localnet using light test-validator, Devnet, and Mainnet-Beta.

Getting Support

For the best support, head to the:

Remember to include as much detail as possible in your question, and please use text (not screenshots) to show error messages so other people with the same problem can find your question!

Next Steps

The ZK Compression primitive is the core of . To leverage ZK Compression, your custom program invokes the Light system program via Cross-Program Invocation (CPI).

First, ensure your development environment has installed Rust, the Solana CLI, and Anchor. If you haven't installed them, refer to this .

We provide tooling for testing your on-chain program on a local Solana cluster. The light test-validator command, available with the , automatically initializes a local Solana cluster with the compression programs, all necessary system accounts, and syscalls activated. By default, it also starts a local Photon RPC instance and Prover node.

for Solana-specific questions

for program and client-related questions

for RPC-related questions

You're now ready to start building with ZK Compression! Head to the section, or !

Solana documentation
The Solana Programming Model: An Introduction to Developing on Solana
Client development
On-chain program development
ZK Compression RPC API
JSON RPC API
here
Helius Labs
Photon indexer implementation
Run a Node
the Light protocol
setup guide
ZK Compression CLI
Web Example Client
Node Example Client
Token Escrow Anchor Program
Solana StackExchange
Light Developer Discord
Helius Developer Discord
Client Quickstart
build
a program
@lightprotocol/stateless.js
@lightprotocol/compressed-token
light-sdk
light-system-program
light-compressed-token
account-compression