# Builder Codes (Front End Fee)

Builder codes allow third-party integrators to permissionlessly earn fees on orders they submit on behalf of users. This enables trading platforms, referral programs, and white-label solutions to monetize their user traffic by providing order flow to the Aftermath ecosystem.

### Overview

**Builder codes** provide a flexible fee-sharing mechanism for integrators building on Aftermath Perpetuals. The system works as follows:

1. **User Authorization**: Users approve specific integrators and set a maximum fee they're willing to pay
2. **Order Submission**: Integrators submit orders on behalf of users, specifying their fee (up to the approved maximum)
3. **Fee Accumulation**: Fees accumulate in per-market vaults as orders execute
4. **Fee Collection**: Integrators claim accumulated fees at any time

Unlike referral codes, builder codes are applied in real time as part of the onchain fee logic.

### How It Works

#### For Users

Users maintain full control over which integrators can earn fees on their orders:

* Approve integrators with a maximum fee cap per integrator
* Revoke permissions at any time
* Set different fee limits for different integrators

#### For Integrators

Integrators must complete a one-time setup before earning fees:

1. Create a fee vault for each market they want to support
2. Get users to approve them as integrators
3. Submit orders with their address and fee amount
4. Claim accumulated fees when desired

#### Fee Structure

* Fees are proportional to taker volume generated by user orders
* Integrators specify their fee when submitting orders (must not exceed user-approved maximum)

### For Developers

**TypeScript.** We've integrated all required builder code functionality into our TypeScript SDK and detailed all functions in our docs.

{% embed url="<https://docs.aftermath.finance/for-developers/typescript-sdk/products/perpetuals/perpetuals#builder-code-integration-methods>" %}

**API.** For more information on how to interact with builder codes through our API, view our API reference.

{% embed url="<https://aftermath.finance/docs>" %}

#### API Endpoints

All builder code endpoints accept POST requests with a JSON body. Base URL: <https://aftermath.finance>

Read your configuration and fee vaults:

* /api/perpetuals/builder-codes/integrator-config
* /api/perpetuals/builder-codes/integrator-vaults

Build transactions for setup and fee collection:

* /api/perpetuals/builder-codes/transactions/create-integrator-config
* /api/perpetuals/builder-codes/transactions/create-integrator-vault
* /api/perpetuals/builder-codes/transactions/claim-integrator-vault-fees
* /api/perpetuals/builder-codes/transactions/remove-integrator-config

Example: Create a fee vault and handle the response

```
## Request
POST https://aftermath.finance/api/perpetuals/builder-codes/transactions/create-integrator-vault
Content-Type: application/json

{
  "walletAddress": "0xYOUR_WALLET_ADDRESS",
    "collateralCoinType": "0x2::sui::SUI",
      "marketId": "0xMARKET_ID"
      }
      
      ## Response
      {
        "tx": {
            "txKind": "<base64-encoded TransactionKind>"
              }
              }
              
              ## Build and submit using the Sui TypeScript SDK
              const tx = TransactionBlock.fromKind(response.tx.txKind);
              const result = await signer.signAndExecuteTransactionBlock({
                transactionBlock: tx,
                });
```

#### Transaction Flow

All transaction endpoints return a serialized transaction kind (txKind). To execute on-chain:

1. Call the transaction endpoint with your wallet address and parameters
2. Receive the txKind object in the JSON response
3. Build a TransactionBlock from the txKind using the Sui SDK
4. Sign the transaction with your wallet
5. Submit to the Sui network via sui\_executeTransactionBlock

#### Integration Modes

There are three ways to integrate builder codes:

* Native API (/api/perpetuals/\*) — Recommended. Full feature set including vault management, fee claiming, and transaction builders.
* TypeScript SDK (@aftermath-finance/sdk) — Typed helper methods for builder code operations. Best for TypeScript applications.
* CCXT-compatible API (/api/ccxt/\*) — Exchange-style endpoints for bot integrations that follow the CCXT standard.
