Overview
The Arcana x402 Agent Marketplace uses Supabase as its primary database for storing:- Chat sessions and messages
- Payment receipts and x402 transaction logs
- Agent ratings and feedback
- Policy controls and decision audit logs
- Procurement provider statistics
Prerequisites
You need a Supabase project before proceeding. Create one at supabase.com if you haven’t already.
Setup Steps
Access Supabase SQL Editor
- Log into your Supabase dashboard
- Select your project
- Navigate to the SQL Editor from the left sidebar
Run SQL scripts in order
Execute the SQL files in the following order. Each file is located in
backend/:supabase-schema.sql- Core chat tablessupabase-query-logs.sql- Payment logs and procurementsupabase-ratings.sql- Rating systemsupabase-agent-policy.sql- Policy controls
Verify tables were created
In the Supabase dashboard, go to Table Editor and confirm all tables are present:
chat_sessionschat_messagesquery_logsx402_payment_logsx402_session_spendx402_tracesx402_trace_stepsx402_procurement_provider_statsx402_procurement_receiptsmessage_ratingsagent_policiespolicy_decision_logs
Database Schema Reference
1. Chat Sessions & Messages
File:supabase-schema.sql
These tables store user chat conversations and message history.
chat_sessions
chat_messages
2. Query Logs & x402 Payments
File:supabase-query-logs.sql
These tables track payment transactions, performance metrics, and procurement records.
query_logs
Tracks response time metrics per query:
x402_payment_logs
Detailed x402 payment receipts with settlement and facilitator data:
This table includes rich audit fields for x402 protocol compliance, including facilitator settlement IDs, payload hashes, and response metadata.
x402_session_spend
Session-level spending snapshots:
x402_traces & x402_trace_steps
Budget tracking and decision logs:
x402_procurement_provider_stats
Provider scoring and circuit breaker state:
x402_procurement_receipts
Procurement receipt ledger:
3. Message Ratings
File:supabase-ratings.sql
message_ratings
User feedback on agent responses:
4. Agent Policy Controls
File:supabase-agent-policy.sql
agent_policies
Policy configuration per agent:
policy_decision_logs
Audit log for policy enforcement decisions:
Row Level Security (RLS)
All tables have RLS enabled but with permissive policies for development:Production RLS Recommendations
- Chat sessions/messages: Restrict to wallet owner
- Payment logs: Read-only for authenticated users, write-only for backend service
- Ratings: Users can only rate their own messages
- Policy tables: Admin-only write access
Indexes
The scripts create performance indexes automatically:idx_chat_sessions_wallet- Fast wallet-based session lookupsidx_chat_messages_session- Efficient message retrieval per sessionidx_query_logs_agent- Agent-specific query performanceidx_x402_payment_logs_session- Session payment historyidx_x402_payment_logs_trace- Trace-based payment lookups- And more…
Troubleshooting
Policy already exists errors
If you see policy-exists errors when re-running scripts, the policy already exists. The scripts useDROP POLICY IF EXISTS guards, but some older versions may not. This is usually safe to ignore.
RLS prevents data access
If your backend cannot write to tables, verify:- You’re using the
SUPABASE_ANON_KEY(not the service role key) - RLS policies are set to allow all operations for development
- Check Supabase logs for specific RLS violations
Migration issues
The scripts include backfill-compatibleALTER TABLE ... ADD COLUMN IF NOT EXISTS statements, making them safe to re-run if you need to update your schema.
Next Steps
- Configure Environment Variables with your Supabase credentials
- Start your Local Development environment
- Deploy Smart Contracts to Base Sepolia