Setup
Local development setup guide for the Pactum platform.
Prerequisites
| Requirement | Version | Purpose |
|---|---|---|
| Node.js | ≥ 18 | Runtime |
| npm | ≥ 9 | Package manager |
| MetaMask | Latest | Wallet interaction (for testing settlement/deposit) |
| Database account | — | Database hosting |
| Arc Testnet USDC | — | Obtained from Circle Faucet |
1. Clone and Install
git clone https://github.com/rizkygm23/pactum.git
cd pactum
npm install
2. Configure Environment
Create a .env.local file in the project root:
cp .env.example .env.local
Fill in the following variables:
| Variable | Description | How to Obtain |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL | Database project URL | Database Dashboard → Settings → API |
NEXT_PUBLIC_SUPABASE_ANON_KEY | Database anonymous (public) key | Database Dashboard → Settings → API |
PACTUM_CONTRACT_ADDRESS | Deployed PactumBilling contract address | From contract deployment output |
NEXT_PUBLIC_PACTUM_CONTRACT_ADDRESS | Same as above, exposed to client | Same as PACTUM_CONTRACT_ADDRESS |
ARC_TESTNET_RPC_URL | Arc Testnet RPC endpoint (optional) | Defaults to https://rpc.testnet.arc.network |
[!NOTE] For full production deployment, the backend requires additional operator credentials. Refer to internal engineering guidelines for production deployment secrets.
[!CAUTION] Never commit
.env.localto version control. The.gitignorealready excludes it.
3. Set Up the Database
Run the SQL migration files in order in the Database SQL Editor (Dashboard → SQL Editor):
database/migrations/001_initial_schema.sql— Core tables and initial RLSdatabase/migrations/002_custom_auth.sql— Custom auth migration (decouples from Database Auth)database/migrations/003_state_channel.sql— Adds status and address columns for state channel billingdatabase/migrations/004_enable_rls.sql— Re-enables RLS on all tables
[!IMPORTANT] Migrations must be executed in numerical order. Each migration depends on the previous one.
4. Deploy the Smart Contract (Optional)
If you need to deploy a fresh instance of the PactumBilling contract:
- Configure
hardhat.config.cjswith your Arc Testnet RPC and deployer private key. - Compile the contract:
node compile.js - Deploy using Hardhat or your preferred deployment tool.
- Update
PACTUM_CONTRACT_ADDRESSandNEXT_PUBLIC_PACTUM_CONTRACT_ADDRESSin.env.localwith the deployed address.
If a contract is already deployed on Arc Testnet, use the existing address.
5. Run the Development Server
npm run dev
The application starts at http://localhost:3000.
6. Verify the Setup
- Signup: Navigate to
/signupand create an account. - Dashboard: After login, you should see the dashboard at
/dashboard. - API Key: Go to Settings and generate an API key.
- Test Usage Tracking: Send a test request:
curl -X POST http://localhost:3000/api/v1/usage/track \ -H "Content-Type: application/json" \ -H "X-API-Key: YOUR_API_KEY" \ -d '{ "model": "test-model", "prompt_tokens": 100, "completion_tokens": 50, "prompt_price_per_token": 0.000005, "completion_price_per_token": 0.000015, "user_address": "0xYOUR_TEST_ADDRESS", "idempotency_key": "test-001" }' - Dashboard Update: The usage event should appear in the dashboard immediately.
Common Issues
| Issue | Solution |
|---|---|
| Database connection fails | Ensure all Database environment variables are properly configured in .env.local. |
| Contract address missing | Settlement and balance checks will be skipped. Set PACTUM_CONTRACT_ADDRESS. |
| MetaMask not on Arc Testnet | Add Arc Testnet to MetaMask: Chain ID 5042002, RPC https://rpc.testnet.arc.network. |
| No test USDC | Visit Circle Faucet to get Arc Testnet USDC. |