PHASE PROTOCOL

PHASE Documentation

How PHASE Protocol works: x402 as an on-chain paywall, NFT creation on Soroban, atomic payment flow, and PHASELQ rewards.

01

What PHASE is

PHASE Protocol turns AI generation into a cryptographic paywall. Every generated NFT requires a verified on-chain payment before the server runs the AI pipeline. There is no subscription, no API key billing, and no way to receive the output without first settling PHASELQ on the ledger.

The system has three pieces: the Forge (create collections + x402 Oracle), the Chamber (settlement, artifact viewer, rewards), and the Dashboard (collection market, listings, per-wallet vault).

RoutePrimary function
/forgeRegister collection + x402-gated AI Oracle
/chamberSettlement, view artifact, collect NFT, PHASELQ rewards
/dashboardCollection market, active listings, per-wallet vault
/explorePublic gallery of all minted NFTs (no wallet needed)
/docsThis page
02

x402: the on-chain paywall

HTTP 402 ("Payment Required") has existed since 1996 but never had a machine-readable standard. x402 gives it concrete meaning: the server responds 402 with a structured payment challenge, the client settles on-chain, and the server verifies the ledger proof before releasing the resource.

In PHASE, x402 is the access gate to the AI Oracle. The server never runs the pipeline speculatively — the Stellar transaction hash is the payment receipt.

Complete x402 flow

Complete x402 flow: browser → 402 challenge → Soroban sign → RPC verification → AI pipeline → mint
StepEndpointActorWhat happens
1. ChallengePOST /api/forge-agentClientServer returns HTTP 402 with amount, token, network
2. PaymentSoroban RPCUser (wallet)Signs PHASELQ transfer → protocol; gets txHash
3. VerificationPOST /api/forge-agentServerReads tx on RPC, decodes invocation, validates amount and payer
4. GenerationExternal APIsServerGemini (lore) + Nano Banana / Pollinations (image)
5. SealPinata IPFSServerUploads metadata JSON, gets permanent CID
6. MintSoroban contractServerCalls initiate_phase, records token_id and owner
03

NFT creation: full lifecycle

Artifact lifecycle

Artifact lifecycle: Register → Pay → Verify → Generate → Mint

The token implements the SEP-50 draft NFT interface on Soroban. All token_id parameters are u32 — required for Freighter SEP-50 compatibility.

FunctionSignatureDescription
owner_of(token_id: u32) → AddressCurrent owner of the token
token_uri(token_id: u32) → StringIPFS metadata URI
token_metadata(token_id: u32) → MapOn-chain artifact attributes
get_creator_collection_ids(creator: Address) → Vec<u64>All collection IDs created by this wallet
get_user_phase(wallet: Address, cid: u32) → u32Token ID minted for that wallet in that collection
create_collection(creator, price, uri)Registers collection — multiple per wallet allowed
initiate_phase(collection_id, minter, uri)Mints the NFT with the sealed IPFS URI
04

PHASELQ: the payment token

PHASELQ is a Stellar Classic asset with a deployed Stellar Asset Contract (SAC). This makes it SEP-41 compatible (callable from Soroban as transfer/mint/balance) and also visible on Horizon as a classic asset with trustlines.

PropertyValue
SymbolPHASELQ
Decimals7 (stroops)
StandardSEP-41 (Stellar Asset Contract)
VisibilitySoroban + Horizon (classic asset)
TrustlineRequired to receive PHASELQ in a wallet
NetworkStellar testnet

The SAC is the token x402 uses as the payment medium. When the user signs the payment transaction, they are calling transfer() on the PHASELQ SAC contract via Soroban.

05

PHASELQ rewards

The /api/faucet endpoint distributes PHASELQ for onboarding and recurring use. Quest eligibility is verified against the ledger — the server does not trust its own store to determine if a quest is complete.

RewardAmountConditionRenewable
genesis10 PHASELQFirst wallet connectionNo (once)
daily2 PHASELQ24-hour windowYes, every 24h
quest_connect_wallet3 PHASELQWallet connectedNo (once)
quest_first_collection3 PHASELQForged a collection or minted in anyNo (once)
quest_first_settle3 PHASELQOn-chain settlement completedNo (once)
06

NFT indexing

Soroban does not expose a native query for "tokens owned by address". PHASE resolves this with two strategies:

Indexing strategy

Indexing strategy: Mercury JWT → Classic REST or RPC scan → NFT list
StrategySpeedDependencyActivation
Mercury ClassicMillisecondsMercury REST + JWTSet MERCURY_JWT in .env
RPC scan (fallback)SecondsPublic Soroban RPCAutomatic without Mercury
07

06 / World Mode (optional)

Collections can activate a narrative world — an optional layer that gives the collection a persistent universe context.

  • world_name and world_prompt are saved off-chain (JSON sidecar)
  • Every mint in that collection injects the world context into Gemini's system instruction
  • An autonomous narrator agent generates a 2-3 sentence narrative connection after each mint
  • Narratives are idempotent — a second call returns the cached result without hitting Gemini
AspectDetail
ActivationToggle in the Forge UI when registering a collection
StorageOff-chain JSON sidecars (worldCollections.json, worldNarratives.json)
Narrator agentPOST /api/narrator — triggered lazily from the Chamber on first load
08

API surface

RouteMethodPurpose
/api/forge-agentPOSTx402 Oracle: return 402 challenge or generate + mint if payment included
/api/x402GET / POST402 challenge + local facilitator
/api/x402/verifyPOSTVerify payment against challenge
/api/x402/settlePOSTSettle payment via facilitator
/api/faucetGET / POSTReward status + PHASELQ distribution
/api/classic-liqGET / POSTTrustline status + classic asset bootstrap
/api/classic-liq/trustlinePOSTSubmit user-signed changeTrust XDR
/api/exploreGETPaginated public NFT gallery
/api/wallet/phase-nftsGETNFTs by wallet (Mercury or RPC scan)
/api/phase-nft/verifyPOSTOn-chain ownership check with backoff
/api/phase-nft/custodian-releasePOSTTransfer custody → wallet (server-signed)
/api/soroban-rpcPOSTProxied RPC with fallback URLs
/api/nft-listingsGET / POSTMarket listings (JSON store)
/api/worldPOSTSave narrative world config for a collection
/api/world/[id]GETFetch world config or null
/api/world/narrative/[token_id]GETFetch saved narrative for a token
/api/narratorPOSTGenerate narrative via Gemini + save (idempotent)
/api/og/chamberGETDynamic Open Graph image for Chamber URLs
09

Security model

The server never holds user keys. All signing happens in the client's wallet. The Soroban contract is the source of truth — ownership, collections, and settlement state are always read from the ledger, not from the server's store.

What the server holdsWhy
ADMIN_SECRET_KEY / FAUCET_DISTRIBUTOR_SECRET_KEYPay faucet rewards (mint or transfer)
PINATA_JWTUpload metadata to IPFS
GOOGLE_AI_STUDIO_API_KEYGemini calls
CLASSIC_LIQ_ISSUER_SECRET (optional)Classic PHASELQ asset bootstrap

x402 verification decodes the actual Soroban transaction — it validates the invocation arguments, payer address, and amount against the challenge parameters. The server does not release AI output based on client assertions.

PHASE · Documentation lives inside the app.