---
title: "Builders"
description: "Earn a fee on the orders your app places for its users: authorize a builder and get an API key for the user's account, place builder orders and read builder fees."
order: 32
llms: trading, account, signing
---

A builder is a Grvt account, usually an app or a bot, that places orders for its users and earns its own fee on
them. Use this page if you run such an app.

How it fits together:

- **Builder account**: your own Grvt main account. Builder fees are paid into it.
- **Authorization**: each user signs once, naming your builder account and the highest builder fee they accept,
  one cap for futures (perpetuals included) and one for spot.
- **Builder order**: an order with `builder` and `builder_fee` set. The user pays the builder fee on each fill,
  on top of the trading fee.

The calls for orders and builder fees are under [Builders](../reference/index.md#builders) in the reference.
Authorizing a builder has no SDK method yet: send it over HTTP as shown below.

## Authorize a builder

**When:** a user connects your app for the first time, or you want to change their fee caps.

One call, `POST /auth/builder/authorize` on the edge host, works in two modes. What you send picks the mode:

| Mode | Use it when | The user signs | Response |
|---|---|---|---|
| **With an API key** | your app trades for the user with its own key | `AddAccountSignerWithBuilder` | `{"api_key": "..."}` |
| **[Authorize only](#authorize-only)** | your app already has a key, or the user changes their caps | `AuthorizeBuilder` | `{}` |

Sending `builder_api_key_signer` and `builder_api_key_permissions` picks the first mode; leaving both out picks
the second. The steps below are for the first.

1. Get two main account IDs (`0x` addresses): the user's and your builder account's.
   [funding_account_summary](../reference/rpc/funding_account_summary.md) returns `main_account_id` for the
   account you are logged in to.
2. Choose the caps, `max_futures_fee_rate` and `max_spot_fee_rate`. Each is a **percentage** string with at
   most 4 decimals: `"0.1"` means 0.1%.
3. Generate a key pair in your app. Its address is the **builder signer**; it must not already be a signer on
   Grvt.
4. Choose the key's permissions on the user's main account: names joined with `&` in this order: `Admin`,
   `InternalTransfer`, `ExternalTransfer`, `Withdraw`, `VaultInvestor`, `Trade`. For example `"Trade"` or
   `"InternalTransfer&Trade"`. Ask only for what you need, usually `Trade`.
5. Have the user sign `AddAccountSignerWithBuilder` ([below](#the-signed-message)) with an admin wallet of
   their main account (Funding Admin).
6. Send it to the edge host. It needs no session: the signature authenticates it.

```sh
export GRVT_DOMAIN=testnet.grvt.io
curl -sS "https://edge.$GRVT_DOMAIN/auth/builder/authorize" \
  -H "Content-Type: application/json" \
  --data @- <<'EOF'
{
  "main_account_id": "0x1111111111111111111111111111111111111111",
  "builder_account_id": "0x2222222222222222222222222222222222222222",
  "max_futures_fee_rate": "0.1",
  "max_spot_fee_rate": "0.05",
  "builder_api_key_signer": "0x4444444444444444444444444444444444444444",
  "builder_api_key_permissions": "Trade",
  "builder_api_key_label": "My trading app",
  "signature": {
    "signer": "0x3333333333333333333333333333333333333333",
    "r": "0x...",
    "s": "0x...",
    "v": 27,
    "expiration": "1767225600000000000",
    "nonce": 1001,
    "chain_id": "326"
  }
}
EOF
```

A success returns HTTP 200 and `{"api_key": "..."}`: an API key on the user's main account, tied to the
builder signer. Log in with it ([Authentication](authentication.md)) and sign the user's orders with the
builder signer's key. [Permissions](accounts.md#permissions) explains what each permission allows on a main
account. [get_authorized_builders](../reference/rpc/get_authorized_builders.md), called on the user's session,
lists your builder account with its caps.

**Watch out:**

- Grvt keeps only a hash of the API key, so this response is the only time you see it. Store it right away.
- To change the caps, use [Authorize only](#authorize-only) with the new values; the first mode would add
  another API key. Authorizing again with the same caps fails with "the builder is already authorized for this
  main account".
- Grvt sets a maximum for the caps. A cap above it, or a negative one, fails with "invalid builder fee rate".
- Permission names out of order (`"Trade&Admin"`) or unknown names fail with HTTP 400.

### Authorize only

**When:** your app already has a way to trade for the user, or the user changes the caps of a builder they
authorized before.

This mode only records your builder account and its caps on the user's main account. It creates no API key.

1. Get the two main account IDs and choose the caps, as in steps 1 and 2 above.
2. Have the user sign `AuthorizeBuilder` ([below](#the-signed-message)) with an admin wallet of their main
   account.
3. Send it to the same route, without the `builder_api_key_*` fields.

```sh
export GRVT_DOMAIN=testnet.grvt.io
curl -sS "https://edge.$GRVT_DOMAIN/auth/builder/authorize" \
  -H "Content-Type: application/json" \
  --data @- <<'EOF'
{
  "main_account_id": "0x1111111111111111111111111111111111111111",
  "builder_account_id": "0x2222222222222222222222222222222222222222",
  "max_futures_fee_rate": "0.2",
  "max_spot_fee_rate": "0.05",
  "signature": {
    "signer": "0x3333333333333333333333333333333333333333",
    "r": "0x...",
    "s": "0x...",
    "v": 27,
    "expiration": "1767225600000000000",
    "nonce": 1002,
    "chain_id": "326"
  }
}
EOF
```

A success returns HTTP 200 and `{}`. The new caps apply to the user's next orders with your builder account.
The cap, signature and same-caps errors are the same as in the first mode.

### The signed message

The domain is the same as for every Grvt signature: `{name: "GRVT Exchange", version: "0", chainId}`, with the
environment's chain ID (326 on testnet, 325 on production). [Signing](signing.md) walks through the hashing.

With an API key, the user signs:

```text
AddAccountSignerWithBuilder(address accountID,address signer,string permissions,address builderAccountID,uint32 maxFutureFeeRate,uint32 maxSpotFeeRate,uint32 nonce,int64 expiration)
```

| Field | From the request |
|---|---|
| `accountID` | `main_account_id` |
| `signer` | `builder_api_key_signer` |
| `permissions` | `builder_api_key_permissions`, the same string (an EIP-712 `string`: its keccak256 hash is encoded) |
| `builderAccountID` | `builder_account_id` |
| `maxFutureFeeRate` | `max_futures_fee_rate` × 10^4: `"0.1"` → `1000`, `"0.001"` → `10` |
| `maxSpotFeeRate` | `max_spot_fee_rate` × 10^4 |
| `nonce` | `signature.nonce`, a random uint32 |
| `expiration` | `signature.expiration`, unix nanoseconds, in the future and at most 30 days ahead |

Authorize only, the user signs:

```text
AuthorizeBuilder(address mainAccountID,address builderAccountID,uint32 maxFutureFeeRate,uint32 maxSpotFeeRate,uint32 nonce,int64 expiration)
```

The fields come from the request the same way: `mainAccountID` is `main_account_id`, and the rest match the
table above.

<details>
<summary>Errors</summary>

Errors come back with an HTTP status and a message:

| Status | Message | Fix |
|---|---|---|
| 400 | `invalid main account ID` / `invalid builder account ID` | Use existing main account IDs (`0x` addresses). |
| 400 | `builder account ID cannot be the same as main account ID` | Use a separate builder account. |
| 400 | `invalid signature` / `signature has expired` / `signature expiration exceeds the maximum of 30 days` | Check the signed fields, the chain ID and `expiration`. |
| 400 | `signature nonce has already been used` | Sign again with a new nonce. |
| 400 | `the main account requires more signatures than provided` | The account needs approvals from several admins ([Approvals by several admins](accounts.md#approvals-by-several-admins)). |
| 400 | `the signer wallet is already in use; please choose a different one` | Generate a new builder signer. |
| 400 | `API key label cannot be empty when permissions or signer are provided` | Set `builder_api_key_label`. |
| 401 | `the signer in the signature is not authorized to represent the main account` | Sign with an admin wallet of the user's main account. |

</details>

## Place builder orders

**When:** your app places an order for a user who has authorized your builder account.

1. Set `order.builder` to your builder main account ID.
2. Set `order.builder_fee` to your fee for this order, a percentage string such as `"0.05"` (0.05%). It must be
   at most the user's cap for this market: the futures cap for perpetuals, the spot cap for spot swaps.
3. Sign and send the order as usual. The SDKs sign `OrderWithBuilderFee` when `builder` is set; by hand, see
   [Builder fee orders](signing.md#builder-fee-orders).

The builder fee is the order's builder fee rate times the trade's notional value, in the quote currency. It is
charged on each fill and paid into your builder account. Spot buys carry no builder fee; spot sells do.

**Watch out:** these errors mean the order was rejected, not placed:

| Code | Name | Cause |
|---|---|---|
| `7504` | `ErrBuilderNotAuthorized` | The user hasn't authorized this builder account. |
| `7505` | `ErrBuilderFeeExceedsAuthorizationLimit` | `builder_fee` is above the user's cap. |
| `7506` | `ErrBuilderMissing` | `builder_fee` is set without `builder`. |
| `7501` | `ErrBuilderFeeNegative` | `builder_fee` is negative. |

## See your builder fees

- On the user's side, each fill has `builder`, `builder_fee_rate` and `builder_fee` (the amount paid, in the
  quote currency): [fill_history](../reference/rpc/fill_history.md).
- On your side, [builder_fill_history](../reference/rpc/builder_fill_history.md) lists the fills where your
  account was the builder. Call it with a session for your builder account; other accounts get an empty list.
