Skip to main content
POST
cURL
ThegetValidityProof RPC method generates zero-knowledge proofs to verify that the given accounts are valid or the new addresses can be created. This proof is required for any operation on compressed accounts (transfer, approve, decompress, etc.) for on-chain verification of compressed state.
You can test this method via the OpenAPI example or custom examples below.
  • Proof limits per request are:
    • hashes: 1, 2, 3, 4, or 8
    • newAddressesWithTrees : 1, 2
  • The newAddresses param field is supported but deprecated. Please use newAddressesWithTreesinstead.
Common Use Cases
  • Token Transfers: Generate proofs required for transferring compressed tokens.
  • Account Operations: Create proofs needed for any compressed account modification.
  • Batch Processing: Generate proofs for multiple accounts in a single call.
  • State Tree Verification: Prove account inclusion in the current state tree.
  • Transaction Building: Obtain proof data needed for compressed transaction instructions.
  • Program Integration: Get validity proofs for custom program operations on compressed accounts.
Parameters
  1. hashes (BN254[], required): Array of BN254 objects representing compressed account hashes to generate proofs for.
  2. newAddresses (BN254[], optional): Array of BN254 objects representing new addresses to include in the proof for address tree verification.
Response The response contains ValidityProofWithContext data:
  • compressedProof (ValidityProof | null): The compressed validity proof object for zero-knowledge verification
  • roots (BN[]): Array of merkle tree roots used in proof generation
  • rootIndices (number[]): Array of indices of the roots in the state tree
  • leafIndices (number[]): Array of indices of the leaves being proven
  • leaves (BN[]): Array of leaf values in the merkle tree
  • treeInfos (TreeInfo[]): Array of information about the state trees used
  • proveByIndices (boolean[]): Array indicating whether to prove by indices for each element
Developer Tips
  • Fetch Accounts First: Always get compressed accounts before generating proofs - you need existing account hashes
  • Batch Processing: You can generate proofs for multiple accounts in a single call. Allowed counts: 1, 2, 3, 4, or 8 accounts
  • Proof Usage: The proof is required for any operation that modifies compressed accounts (transfers, burns, etc.)
  • Caching: Validity proofs are only valid for the current state - don’t cache them for long periods
  • Error Handling: If accounts don’t exist or have been modified, proof generation will fail
  • Integration: Use proof.compressedProof and proof.rootIndices when building transactions
  • State Changes: After any transaction, previously generated proofs become invalid for those accounts
Examples The below examples work - just make sure you installed the dependencies.
Example: Generate Validity Proof Generate a validity proof for compressed accounts.
Example: Proof Generation for Token Transfer Generate a validity proof for a compressed token transfer operation:
JavaScript

Body

application/json
id
enum<string>
required

An ID to identify the request.

Available options:
test-account
jsonrpc
enum<string>
required

The version of the JSON-RPC protocol.

Available options:
2.0
method
enum<string>
required

The name of the method to invoke.

Available options:
getCompressedAccountBalance
params
object
required

Request for compressed account data

Example:

Response

context
object
required
value
integer
default:100
required
Example:

100