# Affiliates

An affiliate is paid half of the platform fee of the purchases it refers, **in the purchase transaction itself**, on chain, as it confirms. There is no account and no sign-up: **any bitcoin address** of the market's network (Taproot, SegWit, nested SegWit or legacy) is an affiliate, except the platform's fee address. Put it in a referral link and share it; the site's `/affiliates` page builds the link for you.

## Referral links

- `https://raresats.net/?ref=<your address>`: any page of the site takes `?ref=`.
- `https://raresats.net/r/<your address>`: a short form, to the home page.

The server remembers the referrer (any usable address, never the fee address) in a first-party cookie, `rs_ref=<address>` (Path=/, SameSite=Lax, Secure), for **24 hours** (`affiliate_cookie_seconds` in `GET /api/market/config`), and redirects to the same page without the referral, so the visitor never sees it in the address bar. **The last link followed wins**: a newer referral replaces yours. When the buyer prepares a purchase, the server reads the cookie.

## From the API

A client of the API names the affiliate directly with the optional `affiliate` field of [Prepare a purchase](https://raresats.net/docs/prepare-purchase.md). It **wins over the cookie**.

```json title="Request"
{
  "listing_ids": ["1031931af1592e1c"],
  "buyer": { "payment_address": "…", "payment_public_key": "…", "ordinals_address": "…" },
  "fee_rate": 4,
  "affiliate": "bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh"
}
```

## The split

The buyer's platform fee is 2.5% of the prices (at least 546 sats), **the same with or without a referrer**: there is no discount. With an applied referral it is paid as **two outputs** instead of one:

| Output | Pays |
| --- | --- |
| `2k+1` | `platform_share` to the fee address |
| `2k+2` | `affiliate_fee` to the affiliate: `floor(fee × affiliate_share_bps / 10000)`, half by default |

Everything else in the [transaction layout](https://raresats.net/docs/concepts.md#the-transaction-layout) is unchanged: the sellers' signed pairs keep their indexes, and the marker stays last. The summary of prepare says what happened:

| `affiliate_status` | Meaning |
| --- | --- |
| `none` | No referrer. |
| `applied` | Paid: `affiliate_fee` sats to `affiliate_address`. |
| `below_minimum` | Each part must be at least **546 sats** (and above its script's dust limit), so a fee under 1,092 sats (prices under about 44,000 sats) is not split: the platform keeps it. |
| `ignored_self` | A self-referral; `affiliate_reason` says which (below). |
| `invalid` | Not a usable address of the network, or the fee address itself. Never a reason to refuse the purchase. |

```json title="summary (excerpt)"
{
  "prices": 60546,
  "platform_fee": 1514,
  "platform_share": 757,
  "affiliate_fee": 757,
  "affiliate_address": "bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh",
  "affiliate_status": "applied",
  "affiliate_reason": null,
  "affiliate_share_bps": 5000
}
```

A purchase is finalized only under the terms it was prepared with: if they change in between, submit answers 409 `config_changed`.

## Self-referral

Self-referrals are not paid. A referral is `ignored_self` when:

| `affiliate_reason` | The check |
| --- | --- |
| `same_address` | The referrer is the buyer's payment or ordinals address. |
| `affiliate_wallet` | The buyer's address is one of the wallet addresses recorded when the affiliate registered (only for an address that used the optional [registration](https://raresats.net/docs/register-affiliate.md)). |
| `linked_funds` | The buyer's coins chosen for the purchase came from a transaction that spent from the affiliate's address (or its registering wallet's, when it registered), or the affiliate's unspent coins came from the buyer's. |
| `unchecked` | That check could not finish in time (it reads a handful of transactions): no split, rather than a split it could not check. |
| `seller` | The referrer is a seller's address or payout in the purchase. |

What cannot be detected: one person using two wallets that never share an address and never exchange coins looks like two unrelated people on chain.

## Your earnings

`GET /api/market/affiliates/{address}` gives your totals (confirmed and pending earnings, volume) and your newest referred purchases: [Get an affiliate](https://raresats.net/docs/get-affiliate.md). Sold events in the [activity](https://raresats.net/docs/get-activity.md) name the `affiliate` they paid. The site's `/affiliates` page builds your link and shows the same.

## Registration (optional)

Registering is no longer needed and pays nothing more. [Register an affiliate](https://raresats.net/docs/register-affiliate.md) still works, for clients written when it was required: the wallet addresses it records only ever count as the affiliate's own wallet (`affiliate_wallet` above).
