# Affiliate Codes vs Referral Codes

Fuul has two distinct code systems: **affiliate codes** for tracking link attribution, and **referral codes** for establishing referrer-user relationships directly. An affiliate code can also be activated as a referral code within a specific project.

## Affiliate codes

An affiliate code is a **personal, branded identifier** that an affiliate uses in tracking links. Instead of sharing a raw wallet address, the affiliate creates a custom code for cleaner URLs.

```
# Without affiliate code (wallet address)
https://yourwebsite.com?af=0x1f9090aae28b8a3dceadf281b0f12828e676c326

# With affiliate code
https://yourwebsite.com?af=my-affiliate-code
```

When a user clicks the link, attribution happens automatically through the pageview → wallet connection flow. The affiliate doesn't need to share a separate code — the link does all the work.

**Example:** A KOL creates the affiliate code `CRYPTO-GUY` and shares tracking links on Twitter. Followers click the link, connect their wallet on the dapp, and all their future conversions are attributed to the KOL — without the user ever typing a code.

|                  | Affiliate codes                                                                       |
| ---------------- | ------------------------------------------------------------------------------------- |
| **Created by**   | Affiliate (requires wallet signature)                                                 |
| **Format**       | User-defined (e.g., `CRYPTO-GUY`)                                                     |
| **Scope**        | Global — one code per affiliate across all Fuul projects                              |
| **How it works** | Embedded in tracking links (`?af=code`), attribution is automatic via pageview events |
| **Best for**     | KOLs, influencers, affiliates sharing links on social media or content                |

{% hint style="info" %}
Create and manage affiliate codes → [Affiliate Links & Codes](https://docs.fuul.xyz/developer-guide/creating-affiliate-links-or-codes)
{% endhint %}

## Referral codes

A referral code is a **code that a user explicitly accepts** to establish a referrer-user relationship. The referred user enters the code in your UI and calls the SDK to accept it — no link click needed.

Referral codes are **generated by the project** on behalf of users via Fuul's API/SDK. They are auto-generated (random 7-character alphanumeric, e.g., `A1B2C3D`) and scoped to a single project.

**Example:** A DeFi protocol generates referral codes for its users. Alice gets code `A1B2C3D` and shares it in a Discord group. Bob opens the dapp, enters Alice's code, and signs a message to accept it. From that point on, Bob's conversions are attributed to Alice.

|                  | Referral codes                                                                                |
| ---------------- | --------------------------------------------------------------------------------------------- |
| **Created by**   | Project generates on behalf of users (via API/SDK)                                            |
| **Format**       | Auto-generated 7-char alphanumeric (e.g., `A1B2C3D`)                                          |
| **Scope**        | Project-specific                                                                              |
| **How it works** | User explicitly accepts the code via SDK/API, creating a permanent referrer-user relationship |
| **Best for**     | In-app referral programs, access gating, community-driven growth                              |

### Use case: access gating (invite codes)

A common pattern is using referral codes as **invite codes** to gate access to a product. Your frontend calls `getReferralStatus` to check whether a user was referred, and only lets them proceed if they were. Fuul doesn't enforce the gate — your application logic does.

**Example:** A perpetuals protocol in closed beta issues referral codes to early users. When someone visits the dapp, the frontend checks their referral status and grants access only if a valid code was used. The restriction lives in the project's own code, not in Fuul.

{% hint style="info" %}
"Invite code" is not a separate code type — it's a referral code used for access gating. The underlying mechanism is identical.
{% endhint %}

## Using an affiliate code as a referral code

An affiliate code is global and lives at the affiliate level. But a project can **activate** an affiliate code as a referral code within its own program — assigning it project-specific properties like maximum uses and rebate rates.

This means a single custom code (e.g., `CRYPTO-GUY`) can work as both:

* An **affiliate code** globally — for tracking link attribution across any Fuul project
* A **referral code** within a specific project — with uses, rebate rate, and other per-project configuration

**Example:** A KOL creates the affiliate code `CRYPTO-GUY`. A DeFi protocol activates that code as a referral code in their program with 100 max uses and a 5% rebate rate. Now the KOL's followers can either click a tracking link *or* enter `CRYPTO-GUY` directly in the dapp — both paths establish the referrer relationship.

{% hint style="info" %}
Think of it as two layers: the **affiliate code** is the identity layer (global, custom, owned by the affiliate) and the **referral code** is the project layer (uses, rebate, scoped per project). When a project activates an affiliate code, it adds the project layer on top.
{% endhint %}

## Side-by-side comparison

|                           | Affiliate code                                      | Referral code                                                                                                      |
| ------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| **Purpose**               | Track link-based attribution                        | Establish referrer-user relationship via code entry                                                                |
| **Created by**            | Affiliate (wallet signature required)               | Project (via API/SDK, on behalf of users)                                                                          |
| **Scope**                 | Global (1 per affiliate)                            | Project-specific                                                                                                   |
| **Format**                | User-defined (e.g., `CRYPTO-GUY`)                   | Auto-generated 7-char (e.g., `A1B2C3D`)                                                                            |
| **How users interact**    | Click a link — no code entry needed                 | Enter and accept a code explicitly                                                                                 |
| **Rebate support**        | Only when activated as a referral code in a project | Yes — via [Sharing Rewards with Referred Users](https://docs.fuul.xyz/core-concepts/referrals/double-side-rewards) |
| **Can become the other?** | Yes — projects can activate it as a referral code   | No — referral codes are always project-generated                                                                   |

{% hint style="info" %}
Both mechanisms create referrer-user relationships and can trigger the same payout rules. The difference is **how the relationship is established**: link click (affiliate code) vs explicit code acceptance (referral code).
{% endhint %}

## Developer guides

* Generate and manage affiliate codes → [Affiliate Links & Codes](https://docs.fuul.xyz/developer-guide/creating-affiliate-links-or-codes)
* Generate, accept, and manage referral codes → [Referral Codes](https://docs.fuul.xyz/developer-guide/referral-codes)
* Track referral links via SDK → [Tracking Referrals in Your App](https://docs.fuul.xyz/developer-guide/tracking-referrals-in-your-app)
