Skip to main content
Builder codes allow you to earn fees when users execute transactions through your application. When placing orders or executing other transactions, you can specify a builder address and fee to receive a portion of the transaction fees.
User Approval Required: Users must approve the maximum builder fee before your application can collect fees. This is a security measure to prevent unauthorized fee collection.
Seven projects are already building on Decibel with Builder Codes. Some bring new ways to trade: Copin lets you discover and copy top perp traders, Samosa puts perps in Telegram, and PulseTrader delivers backtested quant signals you can execute in one click. Others extend what’s possible: Panora aggregates liquidity across Aptos, RNDM deploys AI agents that run autonomous DeFi strategies, Moar provides up to 15x composable leverage, and Tapp adds programmable hooks to the trading stack. See the full ecosystem spotlight for details.

Step 1: Approve Maximum Builder Fee

Before users can pay builder fees, they need to approve a maximum builder fee amount. This is a one-time approval that allows your application to collect fees up to the approved limit:
await dex.approveMaxBuilderFee({
  builderAddr: builderAddress, // Builder's address (64 characters, padded with zeros)
  maxFee: maxBuilderFeeBps, // Maximum fee in basis points (e.g., 10 = 0.1%)
});
Parameters:
  • builderAddr: The address of the builder that should receive the fee. Must be a 64-character hex string (pad with leading zeros after 0x).
  • maxFee: The maximum fee in basis points (1 basis point = 0.01%). For example:
    • 10 = 0.1%
    • 100 = 1%
    • 1000 = 10%

Step 2: Place Order with Builder Codes

Once the builder fee is approved, you can place orders with builder codes:
const orderResult = await dex.placeOrder({
  marketName: "APT/USD",
  price: 300000000,
  size: 1000000000,
  isBuy: true,
  timeInForce: TimeInForce.ImmediateOrCancel,
  isReduceOnly: false,
  // Builder code parameters
  builderAddr: builderAddress, // Same address from Step 1
  builderFee: maxBuilderFeeBps, // Must be <= maxFee from Step 1
});
Builder Code Parameters:
  • builderAddr (optional): The address of the builder that should receive the fee. Must match the address approved in Step 1.
  • builderFee (optional): The fee amount in basis points. Must be less than or equal to the maxFee approved in Step 1.

Important Notes

  • Approval is required first: Users must approve the maximum builder fee (Step 1) before you can use builder codes in transactions (Step 2)
  • Fee limits: The builderFee in Step 2 cannot exceed the maxFee approved in Step 1
  • Address format: Builder addresses must be 64 characters (pad with leading zeros after 0x)
  • Fee calculation: Builder fees are deducted from the user’s transaction fees
  • Payment: Builder fees are paid in the same token as the transaction fees
  • Optional: If no builder address is specified, no builder fee is collected

Example: Placing an Order with Builder Codes

Here’s the complete flow for using builder codes when placing an order using the TypeScript SDK:
import {
  DecibelWriteDex,
  DecibelReadDex,
  NETNA_CONFIG,
  TimeInForce,
} from "@decibeltrade/sdk";
import { Ed25519Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";

// Setup account from private key
const privateKeyHex = process.env.PRIVATE_KEY;
const user = new Ed25519Account({
  privateKey: new Ed25519PrivateKey(privateKeyHex!),
});

// Initialize DEX clients
const dex = new DecibelWriteDex(NETNA_CONFIG, user, {
  skipSimulate: true,
});
const readDex = new DecibelReadDex(NETNA_CONFIG);

// Aptos addresses must be 64 characters (pad with leading zeros after 0x)
const builderAddress =
  "0x0000000000000000000000008c967e73e7b15087c42a10d344cff4c96d877f1d";
const maxBuilderFeeBps = 10; // 10 basis points = 0.1%

// Step 1: Approve builder fee
await dex.approveMaxBuilderFee({
  builderAddr: builderAddress,
  maxFee: maxBuilderFeeBps,
});
console.log("\nBuilder fee approved...");

// Step 2: Place a market order with builder fee
console.log("\nPlacing order with builder fee...");
const orderResult = await dex.placeOrder({
  marketName: "APT/USD",
  price: 300000000, // 3 USD
  size: 1000000000, // 1000 APT
  isBuy: true,
  timeInForce: TimeInForce.ImmediateOrCancel, // Market order
  isReduceOnly: false,
  builderAddr: builderAddress,
  builderFee: maxBuilderFeeBps,
});

if (orderResult.success) {
  console.log(`Order placed! Transaction: ${orderResult.transactionHash}`);
}
For more details on builder fees, see the Builder Fee Transaction Guides.

Resources