Introduction
ETHPayServer is a free, open-source, self-hosted payment processor for Ethereum and EVM-compatible chains. It lets a merchant accept ETH and ERC20 tokens (USDC, USDT, DAI, WBTC, and others) across many EVM chains from a single codebase, without ever handing a spending key to anyone else’s server.
Why it exists
Most “accept crypto” integrations are custodial: you either hold funds in an account you don’t control, or you hand a hosted processor the keys that can move your money. ETHPayServer is built the other way around.
Merchants receive payments directly to addresses derived from their own extended public key
(xpub). The server watches the chain, detects payments, and reports them — but it never
constructs a spending key, never signs a transaction, and cannot move funds. validate_xpub
refuses an extended private key outright, on the version-byte prefix, so a merchant cannot
accidentally hand over the wrong line.
See Non-Custodial Design for how that guarantee is actually enforced in code, not just promised in prose.
What’s in this book
- Quickstart — run the stack locally and create your first invoice.
- Architecture — the API server, the payment monitor, and how they talk to each other.
- Guides — invoices, webhooks, API key scopes.
- API Reference — the full REST API, generated from the server’s own OpenAPI spec.
The repositories
ETHPayServer is split across a few public repositories, each with its own purpose:
| Repository | What it is |
|---|---|
ethpayserver | The API server and payment monitor (this book documents it) |
payserver-client | The web frontend — one client, built to work with any payserver, not only this one |
payserver-commons | Shared types, auth, and crypto used across the above |
All three are MIT-licensed and open to contributions.
Quickstart
This runs the full stack locally: Postgres, Redis, the API server, and the payment monitor.
Prerequisites
- Rust (version pinned via
rust-toolchain.tomlin the repo) - PostgreSQL 14+
- Redis 7+
- An RPC endpoint for at least one chain (a free tier from any provider works for testnets)
1. Clone and start services
git clone https://github.com/agent8-cash/ethpayserver.git
cd ethpayserver
cp docker/.env.example docker/.env
docker compose -f docker/docker-compose.local.yml up -d
2. Run migrations
cargo install sqlx-cli --no-default-features --features postgres
DATABASE_URL="postgres://postgres:postgres@localhost/ethpayserver" \
sqlx migrate run --source data-service/migrations/postgres
3. Run the API server
export DATABASE_URL="postgres://postgres:postgres@localhost/ethpayserver"
export HOST="127.0.0.1"
export PORT="3000"
export ENABLE_SWAGGER="true"
cargo run --release --bin ethpayserver
The server is now at http://localhost:3000, with interactive Swagger UI at /swagger-ui.
4. Run the payment monitor
The monitor is a separate binary — it watches chain activity and publishes events to Redis for the API server to pick up. It can run as one process per chain, or watch several at once.
cargo build --release --bin evmmonitor --features monitor-bin
EVMMONITOR_REDIS_URL=redis://localhost:6379 \
EVMMONITOR_CHAINS=11155111 \
EVMMONITOR_CHAIN_11155111_RPC_HTTP=https://your-sepolia-rpc-url \
EVMMONITOR_CHAIN_11155111_RPC_WS=wss://your-sepolia-ws-url \
RUST_LOG=info \
./target/release/evmmonitor
11155111 is Sepolia’s chain ID. See Supported Networks
for the full list.
5. Create your first invoice
With both processes running, create a store, configure a wallet with your xpub, and create an invoice — see Creating an Invoice for the exact request shapes.
Multiple chains at once
A single evmmonitor process can watch several chains — each gets its own RPC configuration:
EVMMONITOR_CHAINS=11155111,80002,421614
EVMMONITOR_CHAIN_11155111_RPC_HTTP=...
EVMMONITOR_CHAIN_80002_RPC_HTTP=...
EVMMONITOR_CHAIN_421614_RPC_HTTP=...
Each chain can also be given an ordered list of fallback HTTP providers, tried in order if the primary one is rate-limited or down:
EVMMONITOR_CHAIN_11155111_RPC_HTTP_FALLBACKS=https://backup-provider-1,https://backup-provider-2
Architecture
ETHPayServer is two binaries that communicate over Redis, plus a Postgres database.
┌─────────────────────────────────────────────────────────────┐
│ API server (ethpayserver binary) │
│ ├── /health, /stores, /invoices, /auth, /evm │
│ ├── Background services (expiration, cleanup, webhooks) │
│ └── PgDataService — repository implementations │
└─────────────────────────────────────────────────────────────┘
│ Redis pub/sub
▼
┌─────────────────────────────────────────────────────────────┐
│ evmmonitor (separate binary, one or many instances) │
│ ├── Block subscriptions (WebSocket, HTTP polling fallback) │
│ ├── Native + ERC20 transfer detection │
│ ├── Confirmation tracking │
│ └── Reorg detection │
└─────────────────────────────────────────────────────────────┘
│ RPC (HTTP + WebSocket)
▼
one or more EVM chains
Why two binaries
The API server handles HTTP requests, auth, and invoice state. The monitor watches chains for payments and reports what it finds back over Redis. Splitting them means:
- The monitor can run as several instances (one per chain, or sharded), independent of how many API server replicas are running.
- A slow or stalled chain doesn’t block invoice creation, login, or anything else HTTP-facing.
- Either side can restart without losing state — watched addresses and pending confirmations are restored from Postgres.
The non-custodial guarantee
The monitor only ever watches addresses — it’s handed a derived public address to watch for incoming transfers, never a private key. See Non-Custodial Design for how that’s actually enforced, not just a description of intent.
RPC provider resilience
Each chain’s HTTP calls go through an ordered pool of providers: a primary, plus any configured
fallbacks, tried in order on a rate limit, timeout, or 5xx. The pool is sticky — it keeps using
whichever provider last worked rather than round-robining every call — and a provider that just
failed sits out a short cooldown before being retried. See the EVMMONITOR_CHAIN_<id>_RPC_HTTP_FALLBACKS
example in Quickstart.
The real-time WebSocket block subscription does not yet have the same multi-provider failover — only the HTTP request/response path does today.
The repository split
The web frontend (payserver-client) is a
separate repository on purpose: it’s built to talk to any payserver over the same API shape, not
only this one. It has no dependency on this repo, and this repo has no dependency on it — they
communicate purely over HTTP, at whatever URL the client is configured to point at.
Shared types, auth, and crypto primitives used by more than one of these repos live in
payserver-commons, pinned here by git
revision rather than a published version — a change there doesn’t reach this repo until that
pin is deliberately bumped.
Creating an Invoice
curl -X POST https://your-server/invoices \
-H "Authorization: Bearer ak_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"store_id": "00000000-0000-0000-0000-000000000000",
"currency": "USD",
"amount": "25.00",
"expiration_seconds": 900,
"webhook_url": "https://your-server/webhooks/ethpayserver"
}'
Fields
| Field | Required | Notes |
|---|---|---|
store_id | yes | The store this invoice belongs to |
currency | yes | "USD" and other fiat codes, or a crypto asset symbol directly for testing |
amount | yes | Always the currency’s standard human-readable unit — "25.00" for USD, "0.1" for ETH. Never pre-convert to the smallest unit; the server does that internally |
expiration_seconds | no | Defaults to 900 (15 minutes) |
customer_email | no | Used for a payment receipt, if set |
redirect_url | no | Where the customer lands after paying |
webhook_url | no | Where payment events are delivered — see Webhooks |
metadata | no | Arbitrary JSON, echoed back on the invoice |
The full request and response schema, including every field’s type, is in the API Reference.
What happens next
- The server picks (or derives) a payment address from the store’s configured wallet and registers it with the payment monitor.
- The customer sends funds to that address.
- The monitor detects the transfer, and the invoice moves through its status lifecycle as confirmations accumulate.
- If a
webhook_urlwas set, you get notified at each step — see Webhooks.
Checking status
curl https://your-server/invoices/{invoice_id}/status \
-H "Authorization: Bearer ak_your_api_key"
An API key scoped to cancreateinvoice and canviewinvoices is enough to both create and
check the status of invoices — see API Keys & Permissions for the full
permission list and how scoping works.
Webhooks
If an invoice has a webhook_url, the server POSTs a JSON payload to it as the invoice’s
status changes — payment detected, confirmed, cancelled, and so on.
Headers
Every delivery carries:
| Header | Contents |
|---|---|
X-Webhook-Signature | sha256=<hex> — HMAC-SHA256 of the raw body, keyed with your webhook secret |
X-Webhook-Signature-Timestamped | t=<unix>,v1=<hex> — HMAC over "<unix>.<body>", so a reused request older than your tolerance can be rejected even though retries redeliver identical bytes |
X-Webhook-Event | The event type |
X-Webhook-Id | A unique ID for this event |
X-Webhook-Idempotency-Key | Safe to dedupe deliveries on — retries of the same event reuse it |
Verifying a delivery
Recompute the HMAC-SHA256 of the raw request body using your store’s webhook secret, and
compare it — in constant time — against X-Webhook-Signature. Reject anything that doesn’t
match.
import hashlib
import hmac
def verify(raw_body: bytes, signature_header: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, signature_header)
Use the raw request body — not a re-serialized version of the parsed JSON. Reformatting (key order, whitespace) changes the bytes the signature was computed over, and the comparison will fail even for a genuine delivery.
Retries
A delivery that fails (connection refused, timeout, non-2xx response) is retried with backoff. After repeated failures, delivery for that webhook is treated as unreachable rather than retried forever — see the API Reference for the webhook-delivery endpoints that let you inspect and manually replay a specific delivery.
Configuring a webhook per store
Stores can also have a store-level webhook, independent of any single invoice’s webhook_url —
see the store configuration endpoints in the API Reference.
API Keys & Permissions
Two kinds of credentials can authenticate against the API, both as a bearer token:
Authorization: Bearer <token>
- A session token (a UUID) — issued on login, carries the full permissions of the signed-in user’s role on a store.
- An API key (
ak_...) — scoped to exactly the permissions you grant it when creating it, regardless of the owning user’s own role.
Store permissions
| Permission | Grants |
|---|---|
canviewinvoices | Read invoices and their status |
cancreateinvoice | Create invoices |
canmodifyinvoices | Cancel invoices |
canviewpayments | Read payments, payouts, and refund history |
canmanagewebhooks | List and replay webhook deliveries |
canmodifystoresettings | Owner-level store settings — delete/unarchive the store, rotate or configure the wallet |
(Shown without the ethpay.store. prefix the server stores them with internally.)
Scoping a key narrowly
Grant only what the integration actually needs. A webhook-replay cron job, for instance, needs
canmanagewebhooks and nothing else — not canmodifyinvoices, not wallet access. If the key
ever leaks, the blast radius is whatever it was scoped to, not whatever the account that created
it could do.
A key scoped to cancreateinvoice + canviewinvoices is the minimum needed to run the create
→ check-status flow in Creating an Invoice, and nothing more.
Rotation
API keys can be rotated without downtime — create the replacement key, update the integration, then revoke the old one once you’ve confirmed the new one is in use. See the API key endpoints in the API Reference.
API Reference
The full REST API, rendered directly from the server’s own OpenAPI 3 spec — every endpoint,
request/response schema, and field description below comes straight from the server’s
#[utoipa::path] annotations, not hand-written separately. If it drifts from what’s actually
deployed, the spec is wrong, not this page.
Supported Networks
Mainnets
| Network | Chain ID | Native Token |
|---|---|---|
| Ethereum | 1 | ETH |
| Polygon | 137 | POL |
| Arbitrum | 42161 | ETH |
| Optimism | 10 | ETH |
| Base | 8453 | ETH |
| Avalanche | 43114 | AVAX |
| BNB Smart Chain | 56 | BNB |
| zkSync Era | 324 | ETH |
| Linea | 59144 | ETH |
| Scroll | 534352 | ETH |
| Fantom | 250 | FTM |
| Gnosis | 100 | xDAI |
Testnets
| Network | Chain ID | Native Token |
|---|---|---|
| Sepolia | 11155111 | ETH |
| Holesky | 17000 | ETH |
| Hoodi | 560048 | ETH |
| Polygon Amoy | 80002 | POL |
| Arbitrum Sepolia | 421614 | ETH |
| Optimism Sepolia | 11155420 | ETH |
| Base Sepolia | 84532 | ETH |
| Avalanche Fuji | 43113 | AVAX |
| BSC Testnet | 97 | tBNB |
Tokens
Native tokens are supported on every chain above. ERC20 tokens are seeded per-chain into the database by migration — stablecoins and, where unambiguous, WETH/WBTC, each checked against the issuer’s or chain operator’s own published address list rather than a block explorer search.
Query GET /evm/tokens on a running instance for the current list. A store can further
restrict which tokens it accepts with an allowlist or blocklist via
PUT /stores/{id}/token-policy — see the API Reference.
Non-Custodial Design
ETHPayServer never holds a spending key. This isn’t a policy — it’s enforced in code.
How it’s enforced
- Merchants configure a wallet with an extended public key (xpub), not a private key.
validate_xpubchecks the base58 version-byte prefix and refuses an extended private key (xprv) outright — a merchant cannot hand over a spending key even by pasting the wrong line. - Payment addresses are derived from that xpub. The server can compute as many receive addresses as it needs, but derivation from a public key cannot produce a private key for any of them.
- The payment monitor only ever watches addresses for incoming transfers. It has no code path that constructs a transaction, signs one, or broadcasts one in the shipped build.
- The xpub itself is encrypted at rest (envelope encryption, pluggable key provider — a plain secret for a single-VPS deployment, or AWS KMS), not stored in plaintext.
What this means for refunds
Because the server never holds a spending key, it genuinely cannot issue a refund on a
merchant’s behalf — there’s no key to sign one with. The refund API endpoint exists and is
permanently disabled (501 Not Implemented) rather than removed, so integrations get a clear,
documented answer instead of a 404. Refunding a customer is the merchant’s own responsibility,
from their own wallet.
Other security measures
- Address validation (checksum verification) before anything is registered for watching.
- Whitelisted token contracts only — ERC20 addresses are checked against the issuer’s or chain operator’s own published list, not discovered from arbitrary input.
- Confirmation requirements per chain, with reorg detection that re-validates a payment rather than assuming a transaction that disappeared from one block is gone for good.
- Webhook payloads are signed with HMAC-SHA256 — see Webhooks.
- API keys are scoped to exactly the permissions granted at creation — see API Keys & Permissions.
Reporting a vulnerability
This is a public, open-source repository. Please do not open a public issue for an unfixed vulnerability. See the repository’s own security policy for how to report one privately.
Contributing
Contributions are welcome — ethpayserver, payserver-client, and payserver-commons are all
MIT-licensed and open to pull requests.
Before you start
Each repository’s own CLAUDE.md/AGENTS.md is the authoritative contribution guide — read it
first, it covers things that aren’t obvious from the code alone:
ethpayserver/CLAUDE.md— the CI gate, sensitive paths, and conventions that have caused real bugs here before.- Equivalent files in
payserver-clientandpayserver-commons.
A few things worth knowing up front:
- These repos are public. No secrets, internal hostnames, or ticket-tracker links belong in source, comments, or commit messages. Describe why code exists, not where someone explained it internally.
- Sensitive paths are human-reviewed without exception — auth, crypto, wallet/key derivation, migrations, and anything touching movement of funds. A PR touching these is expected and welcome; it just won’t be self-merged.
payserver-commonsis pinned by git revision, not by published version, in the workspaceCargo.tomlof the repos that depend on it. A change there doesn’t reach them until that pin is deliberately bumped.
This documentation site
This book lives in its own repository, agent8-cash/docs,
separate from the code it documents — the same reasoning as the client repo: documentation
should be able to move on its own schedule, and a typo fix here shouldn’t need to go through
ethpayserver’s own CI gate.
Built with mdBook; the API reference page renders the server’s OpenAPI spec via Scalar. To build locally:
cargo install mdbook
mdbook serve