> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gains.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# Bind Code

> Attaches a referrer to a wallet from an EIP-712 signature.

### Endpoint

`POST /api/referrals/bind`

Attaches a referrer to a wallet from an EIP-712 signature.

Only accepted while the wallet has never traded on a covered chain. Afterwards it returns `409 AlreadyTraded`, permanently. Bind at onboarding, before the wallet reaches the exchange. See [Referrals](/developer/integrators/referrals).

### Usage Example

```bash theme={null}
curl -X POST "https://backend-global.gains.trade/api/referrals/bind" \
  -H "Content-Type: application/json" \
  -d '{"message":{...},"signature":"0x..."}'
```

### Response Structure

The generated API panel lists the response schema for status codes: 201, 400, 401, 403, 409, 429, 503. Error responses return an `error` field.


## OpenAPI

````yaml post /api/referrals/bind
openapi: 3.0.3
info:
  title: Gains Network Backend API
  version: 1.0.0
  description: >-
    OpenAPI reference for Gains Network backend-global and public chain-specific
    trading backend endpoints.
servers:
  - url: https://backend-global.gains.trade
    description: Backend Global API
  - url: https://backend-arbitrum.gains.trade
    description: Arbitrum trading backend
  - url: https://backend-base.gains.trade
    description: Base trading backend
  - url: https://backend-polygon.gains.trade
    description: Polygon trading backend
  - url: https://backend-sepolia.gains.trade
    description: Arbitrum Sepolia trading backend
  - url: http://localhost:3002
    description: Local backend-global development server
security: []
tags:
  - name: Health
  - name: Stats
  - name: APR
  - name: Trading History
  - name: Personal Trading History
  - name: Leaderboard
  - name: Holding Rates
  - name: Contests
  - name: Dapp
  - name: Wallet
  - name: Circle
  - name: Solana
  - name: Transak
  - name: Bridge
  - name: Campaigns
  - name: VIP
  - name: Notifications
  - name: Referrals
  - name: Trading Backend
  - name: Legacy Contests
  - name: Rewards
paths:
  /api/referrals/bind:
    post:
      tags:
        - Referrals
      summary: Bind Code
      description: >-
        Attaches a referrer to a wallet from an EIP-712 `BindCode` signature.
        Only accepted while the wallet has never traded on a covered chain;
        afterwards it returns 409 AlreadyTraded permanently. Also available over
        GET, as for Register Code.
      operationId: post_referral-bind-code
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SignedReferralWrite'
      responses:
        '201':
          description: Applied
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: object
                    properties:
                      signer:
                        type: string
        '400':
          description: Malformed message, or signature expired
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Recovered signer is not authorized for the subject
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Origin not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            AlreadyTraded, AlreadyBound, CodeUnknown, SelfReferral, Cycle or
            BadNonce
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: Signed referral writes are disabled, or trade history unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    SignedReferralWrite:
      type: object
      required:
        - message
        - signature
      properties:
        message:
          type: object
          description: >-
            The signed struct plus a `kind` discriminator. `kind` is transport
            metadata and is not part of the EIP-712 struct.
          required:
            - kind
            - code
            - nonce
            - validUntil
          properties:
            kind:
              type: string
              enum:
                - register_code
                - bind_code
            owner:
              type: string
              description: Subject for register_code. Must be the signer.
            referee:
              type: string
              description: Subject for bind_code. Must be the signer.
            code:
              type: string
              description: >-
                Must match ^[a-z0-9_]{1,31}$. Normalize before signing; the
                server rejects rather than normalizing.
            nonce:
              type: integer
              format: int64
              description: >-
                Strictly increasing per signer, shared across both kinds.
                Date.now() in milliseconds works.
            validUntil:
              type: integer
              format: int64
              description: >-
                Unix seconds. Must be in the future and at most 900 seconds
                ahead.
        signature:
          type: string
          description: 65-byte ECDSA signature, 0x-prefixed hex. EIP-1271 is not supported.
    Error:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
        success:
          type: boolean
      additionalProperties: true

````