Skip to content

Builder-code affiliation for x402

Split every payment.

Give the apps that send you paying users a cut, enforced on-chain at settlement. One line on the client, no facilitator of your own to run.

npm install x402aff viem

The kit in four numbers

  • 10%

    default builder cut

    1000 bps, set anywhere from 0 to 10000

  • 1 line

    on the buyer's client

    one extension on the x402 client

  • 0

    contracts to run

    nothing you write, deploy, or audit

  • 7

    mainnet-fork tests

    5 of them adversarial

Off-chain affiliate promises vs. an on-chain split

Before

Off-chain affiliate program

You track referrals in a database, pay out monthly, and ask builders to trust your spreadsheet. You can change the rate, pause payouts, or forget.

  • Payouts wait on your ops.
  • Rates change without notice.
  • Builders cannot verify a thing.

After

x402aff

The payment itself lands in an ownerless 0xSplits contract whose recipients and ratio are fixed at its address. Nobody, including you, can redirect the builder's cut.

  • Split at settlement, in the same USDC transfer.
  • Recipients and ratio baked into the address.
  • Anyone can trigger the payout.

How payment works

Base Builder Codes put three tags on a paid request: a (you, the API), s (the builder that drove it), w (the facilitator). The kit turns s into money with one move.

a
you, the API
s
the builder
w
the facilitator
  1. Step 01Buyer's app

    Request

    The buyer's app calls your route with its builder code in an X-Builder-Code header.

  2. Step 02Your API

    402

    Your server answers with payTo set to the (you, builder) split address. Deterministic CREATE2, same every time.

  3. Step 03CDP facilitator

    Settle

    The stock CDP facilitator settles the buyer's gasless USDC payment straight into the split and writes a/s/w on-chain.

  4. Step 040xSplits

    Payout

    Anyone calls distribute. 10% to the builder, 90% to you. Nobody can change where it goes.

10%

Builder

90%

You

One Affiliation API in TypeScript and Python

Both SDKs ship the same Affiliation facade and resolve the identical split address, asserted byte for byte.

server.ts
npm install x402aff viem
import { Affiliation } from "x402aff";const aff = new Affiliation({ appCode: "bc_yourcode", sellerPayout: "0x..." });// drop-in x402 DynamicPayTo for express, hono, nextapp.use(paymentMiddleware({ payTo: aff.payTo, extensions: aff.extensions }));// release payouts later (permissionless)const { calls, balanceUnits } = await aff.release("bc_alice");

Everything a seller needs, nothing to operate

  • Change the cut

    Basis points, default 1000. Set X402_BUILDER_SHARE_BPS=1500 or pass it in. The ratio is baked into the address, so old funds stay safe at the old ratio.

    Drag to change the cut. Each ratio gets its own split address.

    X402_BUILDER_SHARE_BPS=1000
  • More than two recipients

    Platform fee, partner, referrer. Any allocations that sum to 10000 work; address prediction and distribute follow.

    SplitPlan(recipients, allocations)
  • Release payouts

    aff.pending() finds every builder who paid you straight from CDP's index. No local ledger.

    aff.pending()
  • Claims dashboard

    aff.splits_payload() returns every split, balance, and a permissionless claim, ready for a GET /splits route.

  • Find every kit payment

    The buyer extension stamps a shared x402aff marker, so one SQL query finds every kit-routed payment across all sellers.

    WHERE builder_code = 'x402aff'
  • Any language

    Three view calls against two contracts. Port it to Go or Rust in an afternoon.

    payoutAddress + isDeployed

Money in a split can only reach two addresses

The kit deploys no contracts of its own. It reads two canonical contracts and lets the stock CDP facilitator settle into them. Tested against live Base mainnet on a fork.

Attack on a funded split

  1. Trigger distribute and name yourself the distributor

    Pays out

    Builder 10%, seller 90%, you get 0

  2. Distribute with a tampered struct

    Reverts

    The wallet hash-checks the struct

  3. Deploy a hijacking split at the funded address

    Impossible

    Different params, different CREATE2 address

  4. updateSplit or setPaused to redirect or freeze

    Reverts

    The split is ownerless

  5. Front-run the deterministic deploy

    Pays out

    Same address, same recipients, still pays builder and seller

FAQ

Give builders a reason to send you buyers.

The clay coin machine as an arcade cabinet, a few coins from the narrow chute and a big pile from the wide one