Skip to content
@PHASE-STELLAR

PHASE-STELLAR

PHASE Protocol

PHASE Protocol

AI Artifact Minting Gated by On-Chain Payment — Built on Stellar Soroban with x402

Infrastructure for payment-gated AI artifact creation.

Every AI-generated NFT requires a verified on-chain payment before it exists. No subscription, no custodial API-key billing, and no speculative AI output.

The payment is the key.


What we build

PHASE is a decentralized application where users pay PHASELQ on Stellar to unlock an AI Oracle that generates and mints NFTs.

The protocol combines HTTP 402, x402-stellar, Stellar Soroban, AI generation, and IPFS into a single settlement-gated creation flow.

The server never issues the AI output speculatively.

The core rule: No verified payment, no artifact.

The Soroban ledger proof becomes the payment receipt that unlocks the AI generation and NFT minting pipeline.


Why x402

HTTP 402 (Payment Required) has been reserved since 1996 but was never standardized for machine-to-machine payment flows.

The x402 protocol gives it a concrete meaning:

  1. The server responds with 402 Payment Required.
  2. The response contains a structured payment challenge.
  3. The client settles the required payment on-chain.
  4. The server verifies the ledger proof.
  5. The protected resource is released.

PHASE uses x402 as the access gate to its AI Oracle.


Payment-Gated AI Flow

Client                          Server                        Stellar Testnet
  │                               │                                │
  ├── POST /api/forge-agent ──────▶│                                │
  │                               │                                │
  │◀── 402 Payment Required ──────┤                                │
  │    payment challenge          │                                │
  │    { amount, token, network } │                                │
  │                               │                                │
  ├── User signs Stellar tx ──────────────────────────────────────▶│
  │   PHASELQ transfer            │                            ledger confirms
  │                               │                                │
  ├── POST /api/forge-agent ──────▶│                                │
  │   { settlementTxHash }        │                                │
  │                               ├── verify hash on RPC ─────────▶│
  │                               │◀── owner confirmed ────────────┤
  │                               │                                │
  │                               ├── Gemini lore generation       │
  │                               ├── Image generation             │
  │                               │   Nano Banana / Pollinations   │
  │                               ├── Seal metadata → IPFS         │
  │                               │   Pinata                       │
  │                               ├── create_collection ──────────▶│
  │                               ├── initiate_phase ─────────────▶│
  │                               │                                │
  │◀── artifact URLs + token_id ──┤                                │

NFT Creation Flow

1. Collection registration

Before minting, a creator registers a collection through the PHASE Soroban contract using:

create_collection

Multiple collections per wallet are supported. The contract enforces no collection limit.

Each collection stores:

  • Collection price in PHASELQ stroops
  • Creator address
  • Metadata URI

2. x402 payment challenge

The client calls:

POST /api/forge-agent

with a prompt and no payment header.

PHASE responds with:

HTTP 402 Payment Required

Example challenge:

{
  "protocol": "x402",
  "network": "stellar:testnet",
  "amount": 50000000,
  "token": "C...",
  "facilitator": "https://.../api/x402"
}

The client must settle the required PHASELQ payment before the AI Oracle can be unlocked.


3. Settlement

The user signs the Stellar transaction through Stellar Wallets Kit.

Supported wallets include:

  • Freighter
  • Albedo
  • xBull
  • SEP-7 compatible wallets

The signed XDR is submitted to the Soroban RPC.

The resulting transaction hash becomes the settlement proof.


4. Oracle unlock

The client submits the settlement proof:

POST /api/forge-agent
{
  "settlementTxHash": "..."
}

The server then:

  1. Calls x402-stellar's useFacilitator to verify the payment against the challenge.
  2. Decodes the Soroban event log.
  3. Confirms the payer address.
  4. Confirms the required payment amount.
  5. Calls Google Gemini to generate artifact lore.
  6. Calls Nano Banana for image generation.
  7. Falls back to Pollinations if necessary.
  8. Pins the metadata JSON to IPFS through Pinata.
  9. Calls initiate_phase on the PHASE Soroban contract.
  10. Mints the NFT using the resulting IPFS metadata URI.

The AI generation pipeline therefore occurs after payment verification, not before it.


5. NFT on-chain

Minted artifacts follow SEP-50 draft patterns.

The PHASE contract exposes:

owner_of(token_id: u32)

Returns the current owner.

token_uri(token_id: u32)

Returns the IPFS metadata URI.

token_metadata(token_id: u32)

Returns the on-chain attribute map.

Metadata JSON is SEP-41/50-compatible and readable by wallets and explorers.


Architecture

app/
├── api/
│   ├── forge-agent/     ← x402 AI Oracle: challenge, verify & mint
│   ├── x402/            ← Challenge endpoint, facilitator verification & settlement
│   ├── phase-nft/       ← NFT verification & custodian release
│   ├── wallet/          ← NFT index per wallet
│   ├── faucet/          ← PHASELQ reward distribution
│   ├── explore/         ← Paginated community NFT gallery
│   ├── classic-liq/     ← Classic Horizon asset trustline bootstrap
│   └── soroban-rpc/     ← Proxied RPC with fallback URLs
│
├── forge/               ← Collection creation & Oracle UI
├── chamber/             ← Settlement viewer, NFT collection & reward terminal
├── dashboard/           ← Collection market, listings & vault
└── explore/             ← Community NFT gallery

lib/
├── phase-protocol.ts    ← Soroban contract calls, constants & RPC helpers
├── classic-liq.ts       ← Classic asset trustline utilities
├── mercury-classic.ts   ← Optional Mercury indexer integration
├── phase-copy.ts        ← i18n dictionary (EN/ES)
└── stellar.ts           ← Horizon helpers & trustline checks

contracts/
└── phase-protocol/      ← Rust/Soroban NFT & settlement contract

Indexing strategy

Wallet interfaces frequently lag when indexing Soroban NFTs.

PHASE therefore supports two indexing modes.

Mercury Classic

When MERCURY_JWT is configured, PHASE uses Mercury's REST API to query:

  • Contract events
  • Ledger entries
  • NFT ownership

This provides fast ownership resolution.

RPC fallback

When Mercury is unavailable, PHASE concurrently scans:

owner_of(token_id)

across token IDs.

This is slower but remains fully decentralized and introduces no external indexer dependency.


Soroban RPC resilience

PHASE proxies Soroban simulation calls through:

/api/soroban-rpc

The proxy uses a primary RPC endpoint with configurable fallback endpoints through:

STELLAR_RPC_FALLBACK_URLS

Public Stellar testnet RPC infrastructure can experience congestion and temporary 503 responses.

The proxy absorbs these failures and retries against configured fallback RPC URLs.


Contracts

The PHASE protocol contract is located at:

contracts/phase-protocol/

It is a Rust/Soroban WASM contract implementing the NFT and settlement logic.

Function Description
create_collection(creator, price, uri) Registers a collection. Multiple collections per wallet are allowed.
initiate_phase(collection_id, minter, uri) Mints an NFT after settlement verification.
owner_of(token_id) Returns the current owner of a token.
token_uri(token_id) Returns the IPFS metadata URI.
token_metadata(token_id) Returns the on-chain attribute map.
get_creator_collection_ids(creator) Returns all collection IDs for a creator as Vec<u64>.
get_creator_collection_id(creator) Returns the first collection ID for backward compatibility.
get_user_phase(wallet, collection_id) Returns the phase token ID minted for a wallet in a collection.

PHASELQ

The fungible payment token is PHASELQ.

PHASELQ is implemented as a Stellar Asset Contract (SAC) derived from a Classic Stellar asset.

This makes it SEP-41 compatible and accessible through:

  • Horizon
  • Soroban

The token is used as the payment primitive for the x402-gated AI Oracle flow.


Tech Stack

Area Technology
App framework Next.js App Router, React 19, TypeScript
Styling Tailwind CSS
Chain Stellar Testnet, Soroban WASM contracts
Smart contracts Rust + Soroban SDK
Payments x402-stellar, HTTP 402 challenge/verification
AI Google Gemini, Nano Banana API / Pollinations
Wallet @creit.tech/stellar-wallets-kit
Wallets Freighter, Albedo, xBull, SEP-7 compatible wallets
Indexing Mercury Classic REST, Soroban RPC fallback
Storage Pinata IPFS, multi-gateway display
Stellar SDK @stellar/stellar-sdk

Environment

All contract addresses are loaded from environment variables. Nothing is hardcoded into the application.

Variable Role
NEXT_PUBLIC_PHASE_PROTOCOL_ID PHASE NFT/settlement Soroban contract (C…)
NEXT_PUBLIC_PHASER_TOKEN_ID PHASELQ SAC contract (C…)
PINATA_JWT Server-side IPFS uploads
GOOGLE_AI_STUDIO_API_KEY Gemini lore + image generation
MERCURY_JWT Optional fast NFT indexing via Mercury Classic
STELLAR_RPC_URL Primary Soroban RPC endpoint
STELLAR_RPC_FALLBACK_URLS Comma-separated fallback RPC URLs
ADMIN_SECRET_KEY Faucet issuer keypair for mint mode
FAUCET_DISTRIBUTOR_SECRET_KEY Faucet distributor keypair for transfer mode

See .env.local.example for the complete annotated environment configuration.


Running locally

Install dependencies:

npm install

Create your local environment file:

cp .env.local.example .env.local

Fill in the required contract IDs and API keys, then start the development server:

npm run dev

The PHASE contracts are already deployed on Stellar Testnet.

You do not need to redeploy the contracts to run the application. Configure the existing contract IDs in .env.local.


Network

Stellar Testnet

Network:

Test SDF Network ; September 2015

Default Soroban RPC:

https://soroban-testnet.stellar.org

Core Principle

PHASE makes AI generation a settlement-gated resource.

The sequence is deterministic:

Request
   ↓
HTTP 402
   ↓
PHASELQ payment
   ↓
Stellar ledger confirmation
   ↓
Payment verification
   ↓
AI generation
   ↓
IPFS metadata
   ↓
Soroban mint
   ↓
NFT

There is no AI artifact before the payment is proven.

PHASE Protocol — pay to forge, prove on-chain.

Popular repositories Loading

  1. Phase Phase Public

    PHASE is a decentralized application where every AI-generated NFT requires a verified on-chain payment before it exists. There is no subscription, no custodial API key billing, and no way to receiv…

    TypeScript 5 64

  2. .github .github Public

Repositories

Showing 2 of 2 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…