This document provides a comprehensive guide for deploying all three components of AgenticPay: the Soroban Smart Contracts, the Backend API Server, and the Frontend Web Application.
Before deploying AgenticPay to a production or staging environment, ensure you have the following installed and configured:
- Node.js (v18 or higher) and npm/yarn/pnpm
- Rust and Cargo (for building smart contracts)
- Stellar CLI (for deploying smart contracts to the Stellar network)
- Git
- Process Manager (e.g., PM2) or Docker (if containerizing the backend)
- Third-Party Service Accounts:
- OpenAI (for API keys used in the AI verification engine)
- Web3Auth (for social login integration)
- GitHub Personal Access Token (if elevated API rate limits are required for code fetching)
Each component requires specific environment variables to function correctly.
You need a Stellar account (funded with XLM) for deploying the contracts. Configure the Stellar CLI network and identities:
stellar network add --global mainnet \
--rpc-url https://soroban-testnet.stellar.org \
--network-passphrase "Public Global Stellar Network ; September 2015"
stellar keys generate --global deployerCreate a .env file in the backend/ directory:
PORT=3001
NODE_ENV=production
OPENAI_API_KEY=sk-...
GITHUB_TOKEN=ghp_...
STELLAR_NETWORK=MAINNET
STELLAR_RPC_URL=https://soroban-testnet.stellar.org
SOROBAN_CONTRACT_ID=... # Updated after contract deploymentCreate a .env.local file in the frontend/ directory:
NEXT_PUBLIC_API_URL=https://api.yourdomain.com
NEXT_PUBLIC_WEB3AUTH_CLIENT_ID=...
NEXT_PUBLIC_STELLAR_NETWORK=MAINNET
NEXT_PUBLIC_SOROBAN_CONTRACT_ID=... # Updated after contract deploymentAgenticPay must be deployed in a specific order: Smart Contracts first, then Backend, and finally Frontend, ensuring that dependency references (like Contract IDs) are propagated correctly.
- Navigate to the
contracts/directory:cd contracts - Build the optimized WebAssembly binary:
cargo build --target wasm32-unknown-unknown --release
- Deploy the compiled contract using the Stellar CLI:
stellar contract deploy \ --wasm target/wasm32-unknown-unknown/release/agenticpay_escrow.wasm \ --source deployer \ --network mainnet
- Save the output Contract ID. You will need to add this to both the Backend and Frontend
.envfiles.
The backend can be deployed on any standard VPS (AWS EC2, DigitalOcean, etc.) or PaaS (Render, Heroku).
- Navigate to the
backend/directory:cd backend - Install dependencies:
npm install
- Build the TypeScript code:
npm run build
- Start the server using a process manager like PM2 to ensure it stays running:
npm install -g pm2 pm2 start dist/index.js --name agenticpay-backend pm2 save pm2 startup
The Next.js frontend is ideally suited for deployment on Vercel, but can also be hosted on a standard Node.js server.
Option A: Deploying to Vercel (Recommended)
- Push your code to a GitHub repository.
- Import the project in the Vercel Dashboard.
- Set the Root Directory to
frontend. - Add all environment variables from your
.env.localfile into the Vercel project settings. - Click Deploy.
Option B: Manual Node.js Server Deployment
- Navigate to the
frontend/directory:cd frontend - Install dependencies:
npm install
- Build the production application:
npm run build
- Start the application:
npm start
If an issue occurs after a deployment, follow these rollback procedures for the affected components:
- Vercel: Navigate to the "Deployments" tab in your Vercel project dashboard, find the previous stable deployment, click the vertical dots, and select "Promote to Production".
- Manual: Revert your git working tree to the last stable commit (
git checkout <commit_hash>), runnpm run build, and restart the application (pm2 restart agenticpay-frontend).
- Revert the codebase to the last known stable state:
git checkout <stable_commit_hash>
- Re-build the application:
npm run build
- Restart the backend process:
pm2 restart agenticpay-backend
Smart contracts deployed on Stellar (Soroban) are immutable. "Rolling back" a smart contract involves deploying a new version of the contract and migrating existing services to point to the new Contract ID.
- Revert your contract codebase to the last stable commit.
- Re-build and re-deploy the contract following Step 1 of the deployment process.
- Update the
SOROBAN_CONTRACT_ID(or equivalent) environment variables in both the Backend and Frontend to point to the new Contract ID. - Restart the Backend and redeploy the Frontend to apply the configuration changes. (Note: If the flawed contract holds funds in escrow, manual migration or refund procedures must be executed via the old contract logic if possible).