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.
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.
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:
- The server responds with
402 Payment Required. - The response contains a structured payment challenge.
- The client settles the required payment on-chain.
- The server verifies the ledger proof.
- The protected resource is released.
PHASE uses x402 as the access gate to its AI Oracle.
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 ──┤ │
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
The client calls:
POST /api/forge-agent
with a prompt and no payment header.
PHASE responds with:
HTTP 402 Payment RequiredExample 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.
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.
The client submits the settlement proof:
POST /api/forge-agent
{
"settlementTxHash": "..."
}
The server then:
- Calls
x402-stellar'suseFacilitatorto verify the payment against the challenge. - Decodes the Soroban event log.
- Confirms the payer address.
- Confirms the required payment amount.
- Calls Google Gemini to generate artifact lore.
- Calls Nano Banana for image generation.
- Falls back to Pollinations if necessary.
- Pins the metadata JSON to IPFS through Pinata.
- Calls
initiate_phaseon the PHASE Soroban contract. - Mints the NFT using the resulting IPFS metadata URI.
The AI generation pipeline therefore occurs after payment verification, not before it.
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.
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
Wallet interfaces frequently lag when indexing Soroban NFTs.
PHASE therefore supports two indexing modes.
When MERCURY_JWT is configured, PHASE uses Mercury's REST API to query:
- Contract events
- Ledger entries
- NFT ownership
This provides fast ownership resolution.
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.
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.
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. |
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.
| 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 |
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.
Install dependencies:
npm installCreate your local environment file:
cp .env.local.example .env.localFill in the required contract IDs and API keys, then start the development server:
npm run devThe 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.
Stellar Testnet
Network:
Test SDF Network ; September 2015
Default Soroban RPC:
https://soroban-testnet.stellar.org
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.
