book-spineSDKs

Molecule Protocol Client SDK Documentation

Overview

The @moleculexyz/client-sdk provides type-safe access to Molecule Protocol's GraphQL APIs and subgraphs, specifically for IP-NFTs, IPTokens, crowdsales, and data rooms.

Features:

  • Query IPTs, markets, and IP-NFTs

  • Manage data room files (upload, encrypt, retrieve)

  • Interact with crowdsale data

  • Handle authentication with Privy tokens

Limitations:

  • Does not execute on-chain transactions. For this, use @moleculexyz/onchain + wagmi.

  • Does not custody keys or manage wallets.

  • Does not replace contract interactions for writes.

Supported Environments:

  • Node.js 18+

  • Browser (ESM)

  • React/Next.js

Relationship to Contracts:

Contracts are the definitive source. This SDK queries indexed data from APIs and subgraphs for convenience. For on-chain writes, use the contract ABIs directly with viem/wagmi.

Installation

Peer Dependencies:

Quickstart

This example demonstrates how to upload a file to a data room, a real write operation you can complete in under 10 minutes:

Prerequisites:

  • Privy authentication token (from @privy-io/react-auth)

  • Wallet address

  • An IP-NFT you have access to

Core Abstractions

Understanding these concepts helps you use the SDK effectively:

SDK Concept
On-chain Equivalent

IPT

IPToken ERC-20 contract

IP-NFT

IP-NFT ERC-721 token

Market

Uniswap/DEX pool for an IPT

CrowdSale

CrowdSale contract instance

DataRoom

Off-chain encrypted storage tied to an IP-NFT

ProjectV2

Lab/project metadata in the API

Client

The DesciSdk client wraps all domain APIs:

Modules:

  • tokens: IPT queries with market data

  • ipnfts: IP-NFT queries

  • labs: Data room & project management

  • crowdsales: Crowdsale data from subgraph

  • minting: IP-NFT minting flow

  • tokenizer: IPT creation flow

Authentication Modes

Unauthenticated (public data):

  • sdk.tokens.getAllWithMarkets()

  • sdk.ipnfts.getById(id)

  • sdk.crowdsales.getById(id)

Authenticated (requires identityToken + walletAddress):

  • sdk.labs.getPassphrase(ipnftUid)

  • sdk.labs.initiateFileUploadV2(...)

  • sdk.minting.reserve()

Common Workflows

Display IPT Market Data

Upload Encrypted File to DataRoom (Onchain-Verified Envelope Encryption)

New uploads use Molecule's Onchain-Verified Envelope Encryption. The backend issues a one-shot plaintext DEK on initiate; the client encrypts AES-256-GCM locally and stores the wrapped DEK + access conditions on finalize. accessControlConditions is a JSON-stringified array of predicates evaluated against AccessResolver at decrypt time β€” see Data Privacy & Access β€” Worked Example for the full shape.

Role grants happen on-chain via the AccessResolver contract, not through this SDK. Use viem / ethers to call grantRole(oclId, account, role, expiry, isAgent) from the Lab owner; once granted, the file's hasRole condition resolves true for the grantee at decrypt time.

Upload Encrypted File (Lit Protocol, legacy)

Legacy. The flow below is retained for files encrypted before the migration to Onchain-Verified Envelope Encryption. New uploads should use the path above.

Check Crowdsale Contribution

Batch Read: IPTs Owned by Address

Transactions & Signing

Read vs Write

Operation
Type
Auth Required
On-chain

sdk.tokens.getAllWithMarkets()

Read

No

No (API)

sdk.crowdsales.getById()

Read

No

No (Subgraph)

sdk.labs.initiateFileUploadV2()

Write

Yes

No (API)

sdk.labs.finishFileUploadV2()

Write

Yes

No (API)

Who Signs What

The SDK:

  • Handles API authentication (Privy JWT tokens).

  • Utilizes presigned upload URLs (S3).

For on-chain transactions (minting, tokenizing, bidding), use viem/wagmi with the contract ABIs from @moleculexyz/common/abis.

Confirmation Model

SDK API calls are confirmed when the Promise resolves - these are off-chain operations. For on-chain confirmations, use wagmi's waitForTransactionReceipt.

Error Handling

Error Types

Common Errors and Fixes

Error
Cause
Fix

AuthenticationRequiredError

Missing identityToken

Pass auth config to createDesciSdk()

AuthorizationError

No access to resource

Check wallet owns/has access to IP-NFT

NotFoundError

Invalid ID

Verify ipnftUid format: {contract}_{tokenId}

NetworkError

API unreachable

Retry with exponential backoff

Retry Guidance

API Reference

DesciSdk

Main client class.

Key Methods

API
Method
Description

tokens

getAllWithMarkets()

All IPTs with market data

tokens

getById(id)

Single IPT by contract address

ipnfts

getById(uid)

IP-NFT by {contract}_{tokenId}

ipnfts

getByOwner(address)

All IP-NFTs for wallet

labs

getAll()

All projects

labs

getPassphrase(uid)

DataRoom encryption key (auth)

labs

initiateFileUploadV2()

Start file upload (auth)

labs

finishFileUploadV2()

Complete file upload (auth)

crowdsales

getById(id)

Crowdsale details

crowdsales

getContribution(saleId, user)

User's contribution

Full TypeScript types are included in the package.

Versioning & Compatibility

SemVer Policy

  • Major: Breaking API changes

  • Minor: New features, backward compatible

  • Patch: Bug fixes

SDK ↔ Contract Compatibility

SDK Version
Contract Compatibility

0.x

IPNFT v2.5, Tokenizer v1.4, CrowdSale v1.x

The SDK queries indexed data. Contract upgrades may require SDK updates for new fields/events.

Breaking Change Policy

Breaking changes are announced in release notes with migration guides. We maintain backward compatibility for at least one minor version when possible.

Last updated