Phi
  • Introduction
    • What is Phi
    • Our journey
    • Getting Started
    • Supported Chains
    • Support File Format
    • FAQ
  • Phi Board
    • Overview
  • Getting Started
  • Creating Boards
  • Backdrops and Backgrounds
  • Verified and Pinned Board
  • Board Mint Referrals
  • Phi Protocol
    • Overview
    • User Groups
    • What is Cred?
    • Cred Share
    • Understanding Verification
    • Signature Verifier
    • Reward Breakdown
    • Mint Referral
    • Participant Management
    • Featured Activity
  • USER GUIDE
    • Create Cred
    • Create Verifications
    • Curate Cred
    • Submit Your Art
    • Claiming Rewards
    • Split.xyz
  • Case Study
    • Advanced Art - GasFire
  • DEVELOPERS
    • Architecture
    • API
    • Phi SDK
    • Merkle Claim Flow
  • others
    • Audit
    • Media Kit
    • Term of Service
    • Privacy Policy
  • Official Links
    • Warpcast
    • Github
    • Philand
    • Discord
    • X
Powered by GitBook
On this page
  • Create and Claim Cred Merkle Type Process
  • Creation Process
  • Claim Process
  • Key Points of the MerkleClaim Function:
  1. DEVELOPERS

Merkle Claim Flow

PreviousPhi SDKNextAudit

Last updated 7 months ago

Create and Claim Cred Merkle Type Process

This document explains the process of creating and claiming a Cred Merkle type, based on the provided sequence diagrams and smart contract code.

Creation Process

Overview

The creation process involves interaction between four main components:

  1. Contract

  2. Frontend

  3. Backend

  4. Arweave (decentralized storage)

Step-by-Step Creation Process

  1. Request Signature: Frontend initiates the process by requesting a signature.

  2. Upload CSV: Backend uploads a CSV file with addresses to Arweave.

  3. Create and Upload Merkle Tree: Backend creates a Merkle tree from the CSV data and uploads it to Arweave.

  4. Upload Cred Metadata: Backend uploads the credential metadata to Arweave.

  5. Create and Response Signature: Backend creates a signature and sends it to the Frontend.

  6. Call "createCred" Method: Frontend calls the createCred method on the Contract.

Claim Process

Overview

The claim process allows eligible users to claim their credentials using Merkle proofs.

Step-by-Step Claim Process

  1. Request Proof: Frontend requests a proof for claiming.

  2. Fetch Cred Metadata: Backend retrieves credential metadata from Arweave.

  3. Fetch Merkle Tree: Backend fetches the Merkle tree from Arweave.

  4. Load Merkle Tree & Find Proof: Backend processes the Merkle tree and finds the proof:

    javascriptCopyconst json = await (await fetch(cred.verification.merkle_tree)).json();
    const tree = loadMerkleTree(json);
    
    let proof, data;
    for (const [i, v] of tree.entries()) {
      if (v[0].toLowerCase() == minter) {
        proof = tree.getProof(i) as Hex[string][];
        data = v[1];
      }
    }
    
    if (!proof) {
      return new Response("Not Eligible", { status: 400 });
    }
  5. Response Proof: Backend sends the proof back to the Frontend.

  6. Call "claim" Method: Frontend calls the merkleClaim method on the Contract.

Key Points of the MerkleClaim Function:

  1. Input Parameters:

    • proof_: Merkle proof

    • encodeData_: Encoded data containing minter address, referral address, and art ID

    • mintArgs_: Minting arguments including quantity and image URI

    • leafPart_: Additional data for the Merkle leaf

  2. Verification:

    • Checks if the minter address is valid and the verification type is "MERKLE"

    • Verifies the Merkle proof using MerkleProofLib.verifyCalldata

  3. Claim Processing:

    • Validates and updates the claim state

    • Processes the claim, which likely includes minting the NFT

  4. Event Emission:

    • Emits an ArtClaimedData event with relevant information

Conclusion

The Cred Merkle type creation and claim process provides a secure and efficient way to distribute credentials to eligible addresses. The use of Merkle trees allows for gas-efficient verification on-chain, while storing larger datasets off-chain on Arweave ensures data availability and reduces on-chain storage costs.