// book 37
patriola.com

Book 37 · Patriola’s Guide to Claude

Kaspa Affiliate Systems


Secure Kasplex EVM affiliate commissions with Lambda. The private key never touches the web server — a real production system, built with Claude, decision by decision.

Buy Ebook on Amazon

Patriola's Guide to Claude — Kaspa Affiliate Systems: Secure Kasplex EVM Affiliate Commissions with Lambda
What this book is

A private key that never touches the web server

Running an affiliate program from shared hosting sounds simple until you need to pay commissions on-chain. A private key on a web server is a liability — PHP error logs can leak environment variables, shared hosting doesn't isolate tenants at the process level, and a key that touches the filesystem is a key that's already one misconfiguration away from exposure.

This book builds a complete affiliate system that solves that problem by design: the private key lives in AWS Lambda, encrypted at rest by KMS, and the web server never sees it. Lambda holds the key and signs transactions when the web server calls it; the web server holds only a rotatable API secret for authenticating those calls.

The on-chain layer is a Solidity contract deployed on the Kasplex zkEVM Layer 2: affiliate registration, commission tracking in basis points, automatic payouts when the contract has funds, and pending accrual when it doesn't. Affiliates can withdraw their pending balance directly from the contract without the owner's involvement. Every chapter draws from real deployed code — not a tutorial scaffold but a system running in production.

What you’ll learn

The full stack, decision by decision

  • The contract — AffiliatePayouts.sol: basis-points commission math, the auto-pay vs. pending-accrual logic, and the available-balance invariant that keeps payouts honest.
  • Deploying to Kasplex — Hardhat config, chain ID, and gas tuning for the Kasplex zkEVM Layer 2.
  • Lambda as a signing layer — KMS-encrypted key custody, IP whitelisting, an API secret instead of a key on the web server, and action routing.
  • The ensure-and-sale pattern — Idempotent affiliate registration before recording a sale, closing the race condition that breaks naive implementations.
  • Commission flow — Auto-pay versus pending accrual, affiliate self-withdraw, and the owner's flush operation.
  • PHP integration — Calling Lambda from shared hosting, config management, and error handling that fails safely.
  • Admin operations — Funding the contract, updating commission rates, and deactivating affiliates, all through Lambda actions.
  • Verification — Reading on-chain state, confirming events, and building confidence before go-live.
From the book

A preview

A private key that touches the filesystem is a key that's already one misconfiguration away from exposure. The fix isn't a better secrets manager on the web server — it's removing the key from the web server entirely.
You Why not just keep the private key in an encrypted env var on DreamHost and call it a day?
Claude Because shared hosting doesn't isolate tenants at the process level, and PHP error logs are exactly the kind of place a stray var_dump or misconfigured logger ends up leaking an environment variable. Encryption at rest on the same box the app runs on only protects against a narrower set of failures than moving the key off that box. Lambda with KMS means the key is never resident where your PHP code executes at all — the web server authenticates with a secret it can rotate, and the worst a leaked secret buys an attacker is a call to a scoped Lambda action, not a signing key.
Who it’s for

Builders running a real affiliate program on shared hosting

This book is for readers already comfortable with Solidity basics, AWS Lambda, and PHP on shared hosting who want the architectural decisions and production-specific patterns, not an introduction to any of the three. By the end you have a documented path for keeping a signing key off a web server entirely, a contract design with the invariants that keep commission math honest, and the idempotency pattern that prevents a registration race from breaking sales in production.

A longer excerpt is available to newsletter subscribers.

Buy Ebook on Amazon

Stay current

New books in this series

One short email per book launch.