Merchant setup
Deploy to a server
Run the published package on a server with systemd or pm2, nginx, and TLS.
Run the published package on an Ubuntu 24.04 server with systemd or pm2, and put nginx in front for TLS. This example binds the gateway to 127.0.0.1 and uses gateway.example.com. agent-commerce start runs it, so you need no repository clone, build step or start script. To run it in a container instead, use the container image.
data/; a second startup with ACP enabled can mark active checkouts unresolved.Prepare the server
The package requires Node.js 22 or newer; Ubuntu 24.04 provides Node 18. Install Node 22 from NodeSource, then create a service user with no login shell:
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
node --version # v22 or newer
sudo useradd --system --create-home --home-dir /srv/agent-commerce \
--shell /usr/sbin/nologin agent-commerceInstall the gateway
Work in a shell as the service user, so it owns everything you create:
sudo -u agent-commerce -H bash
cd ~ # /srv/agent-commerce
mkdir -m 700 data
npm install @devlab.group/[email protected] @x402/[email protected] @x402/[email protected] [email protected] @modelcontextprotocol/[email protected]Install the pinned x402 and MCP peers with the package. Omit @modelcontextprotocol/server if MCP is disabled. For Solana or NEAR offers, MPP or AP2, add the peers listed in Installation. Keep package-lock.json so npm ci can reproduce the install.
Configure it
version: 1
merchant:
id: my-store
name: My Store
publicBaseUrl: ${GATEWAY_PUBLIC_BASE_URL}
server:
port: 8080
host: 127.0.0.1 # only nginx, on the same host, reaches it
adminToken: ${ADMIN_TOKEN}
allowedOrigins: []
storage:
receipts:
driver: sqlite
path: /srv/agent-commerce/data/receipts.sqlite
protocols:
http:
enabled: true
mcp:
enabled: true
mountPath: /mcp
resources:
premium_report:
name: Premium Report
description: A paid endpoint on your existing backend.
input:
type: object
properties: {}
additionalProperties: false
backend:
type: http
method: GET
url: ${MERCHANT_API_BASE_URL}/api/report
timeoutMs: 10000
pricing:
type: fixed
amount: "0.01"
currency: USDC
expose: [http, mcp]
payments: [x402]
payments:
x402:
enabled: true
network: eip155:84532
rpcUrl: https://base-sepolia-rpc.publicnode.com # health checks and reconcile
payTo: ${MERCHANT_WALLET} # no asset fields: the network's USDC
maxTimeoutSeconds: 300
facilitator:
mode: remote
url: https://x402.org/facilitator
auth: { type: none }This binds the gateway to loopback, stores receipts in data/, and uses the public facilitator for Base Sepolia. For mainnet, change the payments block as Networks & facilitators shows. Since 2.6.0, the receipt database also holds ACP claims, AP2 holds and pending A2A tasks, and since 2.9.0, retained A2A task responses.
Secrets go in an environment file next to it:
umask 077 # the files you create next are readable by their owner only
cat > .env <<EOF
NODE_ENV=production
LOG_LEVEL=info
GATEWAY_PUBLIC_BASE_URL=https://gateway.example.com
ADMIN_TOKEN=$(openssl rand -hex 32)
MERCHANT_API_BASE_URL=https://api.example.com
MERCHANT_WALLET=0xYourWalletAddress
EOFNODE_ENV=production switches the logs to one JSON object per line. Replace the example wallet address and backend URL before validating. Keep the file to plain KEY=value lines so systemd and Node can both read it.
Validate it, then try a first run by hand:
npx @devlab.group/agent-commerce validate --config config.yaml --env-file .env
npx @devlab.group/agent-commerce start --config config.yaml --env-file .env # Ctrl+C to stop
exit # back to your own userRun it as a service
systemd starts the gateway at boot and restarts it after a failure. These settings restrict writes to data/ and a private temporary directory.
[Unit]
Description=Agent Commerce Gateway
After=network-online.target
Wants=network-online.target
[Service]
User=agent-commerce
Group=agent-commerce
WorkingDirectory=/srv/agent-commerce
EnvironmentFile=/srv/agent-commerce/.env
ExecStart=/usr/bin/node /srv/agent-commerce/node_modules/.bin/agent-commerce start --config /srv/agent-commerce/config.yaml
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
# Writes are limited to data/ and a private temporary directory
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ReadWritePaths=/srv/agent-commerce/data
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now agent-commerce
systemctl status agent-commerce
journalctl -u agent-commerce -f # logssystemd loads the variables from .env. On stop or restart, SIGTERM lets the gateway drain requests before closing storage. Set TimeoutStopSec above your slowest settlement plus backend call so systemd allows enough time before SIGKILL. Check NodeSource's Node installation at /usr/bin/node with which node.
If your server already uses pm2, run it as the service user. Its startup unit restores the saved process list after a reboot. This setup does not apply the systemd tab's write restrictions.
module.exports = {
apps: [
{
name: 'agent-commerce',
cwd: '/srv/agent-commerce',
script: 'node_modules/.bin/agent-commerce',
interpreter: 'node',
args: ['start', '--config', 'config.yaml', '--env-file', '/srv/agent-commerce/.env'],
env: { NODE_ENV: 'production' },
exec_mode: 'fork', // never cluster: one process per set of data files
instances: 1,
autorestart: true,
kill_timeout: 30000, // time for a graceful shutdown before SIGKILL
},
],
};sudo npm install -g pm2
sudo -u agent-commerce -H pm2 start /srv/agent-commerce/ecosystem.config.cjs
sudo -u agent-commerce -H pm2 save
sudo pm2 startup systemd -u agent-commerce --hp /srv/agent-commerce
sudo -u agent-commerce -H pm2 logs agent-commercestart --env-file loads .env before the gateway reads its config. Existing environment variables take precedence, so the ecosystem file also sets NODE_ENV. pm2 sends SIGINT on stop and waits for kill_timeout before forcing a shutdown. The example raises that limit from 1.6 to 30 seconds.
Put nginx and TLS in front
Point the hostname's DNS record at the server first, so certbot can issue the certificate.
limit_req_zone $binary_remote_addr zone=agent_commerce:10m rate=10r/s;
server {
listen 80;
listen [::]:80;
server_name gateway.example.com;
client_max_body_size 256k; # match the gateway request limit
location / {
limit_req zone=agent_commerce burst=20 nodelay;
limit_req_status 429;
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host; # keep it: the gateway checks Host
proxy_buffering off; # MCP responses may stream events
}
}sudo apt-get install -y nginx certbot python3-certbot-nginx
sudo ln -s /etc/nginx/sites-available/agent-commerce /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d gateway.example.com --redirect
sudo ufw allow OpenSSH && sudo ufw allow 'Nginx Full' && sudo ufw enablepublicBaseUrl hostname and loopback names. Without this line, nginx forwards Host: 127.0.0.1:8080. Every proxied request then looks local, bypassing the gateway's DNS rebinding check.The gateway has no built-in rate limit. Tune nginx's rate and burst for your traffic. ACP checkout also needs TLS to protect its bearer token in transit.
With ERC-8409 quotes enabled, a small challenge header can reach about 2.5 KB with one offer or 4.9 KB with three, depending on metadata. Set proxy_buffer_size to fit the response headers; nginx rejects headers larger than this buffer, which defaults to one 4 or 8 KB memory page. Clients echo quotes in PAYMENT-SIGNATURE. With six quoted offers, that header can reach about 7.4 KB, close to the default 8 KB per-field limit set by large_client_header_buffers. Measure both headers with your offers and resource metadata.
Check it
curl -s https://gateway.example.com/health
curl -s https://gateway.example.com/ready
curl -s https://gateway.example.com/.well-known/agent-commerceThen on the server:
sudo -u agent-commerce -H bash
cd ~
npx @devlab.group/agent-commerce doctor --config config.yaml --env-file .env --gateway http://127.0.0.1:8080doctor exits non-zero if a check fails, so you can use it in a deploy script. Review the go-live checklist before sending real traffic to the server.
Operate it
| Task | systemd | pm2 |
|---|---|---|
| logs | journalctl -u agent-commerce | pm2 logs agent-commerce |
| apply a config or secret change | sudo systemctl restart agent-commerce | pm2 restart agent-commerce |
| stop | sudo systemctl stop agent-commerce | pm2 stop agent-commerce |
Run the pm2 commands as the service user. The configuration is read once at startup, so every change needs a restart; LOG_LEVEL=debug adds detail while you investigate.
- Upgrade: as the service user, rerun the install command with the exact new version, such as
@devlab.group/agent-commerce@x.y.z. Check dependency versions withnpx @devlab.group/agent-commerce version, then restart. If the receipt schema is incompatible, the gateway fails at startup. 2.9.0 migrates the database to schema v6, which 2.6 to 2.8 cannot open: back up before the first start. Minor releases may break experimental features (MPP, ACP, AP2, the a2a-x402 extension, ERC-8409 quotes, the public resource URL and Bazaar metadata, the store methods added in 2.6.0 and 2.9.0, theidempotencysettings added in 2.7.0,import openapi,export mcp-registryanddoctor --registry). Test upgrades before deployment. Before upgrading from 2.5, back up and keep the legacy store keys for the first start; see Upgrade from 2.5. - Back up: run
agent-commerce backupas the service user, including while the gateway runs, then copy the backup off-server. Since 2.6.0, one receipt snapshot includes AP2 holds and ACP claims, and since 2.9.0, A2A tasks. Deleting spent mandate rows can permit reuse.
sudo -u agent-commerce -H bash
cd ~
npx @devlab.group/agent-commerce backup --config config.yaml --env-file .env --out "backup-$(date +%F-%H%M)"The service user owns the new 0700 backup directory and its 0600 files. backup.json records SHA-256 hashes. Copy the backup off-server, then remove the local copy. For restore steps, see Storage.