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

# Build onboarding transaction

> Build the sponsor-funded onboarding transaction for a classic G-address: creates the account if needed and establishes the USDC trustline. The facilitator returns the unsigned transaction XDR for the user to sign and submit via `POST /stellar/onboard/submit`.

If the account is already fully onboarded, `nothingToDo: true` is returned and no XDR needs to be signed.



## OpenAPI

````yaml /api-reference/openapi.json post /stellar/onboard/build
openapi: 3.1.0
info:
  title: Buckspay Facilitator & BFF API
  version: 0.2.0
  description: >-
    HTTP wire contract for the Buckspay SDK. The SDK calls these endpoints
    internally via `@buckspay/relayer`; this reference is for teams building
    their own BFF relay route or calling the facilitator from server-side code.


    All facilitator endpoints require the `x-api-key` header. **The API key is a
    server-side secret - it must only appear in BFF or server-side code and must
    never be shipped to a browser bundle.** Use `createRelayRoute` and
    `createSignerProxyRoute` from `@buckspay/nextjs` to build compliant BFF
    handlers.
servers:
  - url: '{facilitatorUrl}'
    description: >-
      Buckspay facilitator (all endpoints). Set via BUCKSPAY_FACILITATOR_URL on
      the server.
    variables:
      facilitatorUrl:
        default: https://facilitator.buckspay.xyz
        description: Base URL of the Buckspay facilitator service.
security:
  - FacilitatorApiKey: []
tags:
  - name: Relay
    description: >-
      Submit a signed Soroban authorization entry for gasless relaying to the
      Stellar network.
  - name: Fee
    description: >-
      Quote the fee-token amount required for gas-in-token (token gas mode)
      before building the forward() invocation.
  - name: Account State
    description: Read on-chain state for classic G-addresses and contract C-addresses.
  - name: Onboarding
    description: >-
      Build and submit the sponsored onboarding transaction; deploy passkey
      smart-accounts and policy session-accounts.
  - name: Auth
    description: >-
      Signer-proxy for social and email authentication. The BFF forwards these
      requests to the facilitator; provider secrets remain server-side.
  - name: Swap
    description: >-
      Quote a gasless EVM token swap. Requires `swapChain` to be configured in
      the relayer.
paths:
  /stellar/onboard/build:
    post:
      tags:
        - Onboarding
      summary: Build onboarding transaction
      description: >-
        Build the sponsor-funded onboarding transaction for a classic G-address:
        creates the account if needed and establishes the USDC trustline. The
        facilitator returns the unsigned transaction XDR for the user to sign
        and submit via `POST /stellar/onboard/submit`.


        If the account is already fully onboarded, `nothingToDo: true` is
        returned and no XDR needs to be signed.
      operationId: postStellarOnboardBuild
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OnboardBuildRequest'
      responses:
        '200':
          description: Onboarding transaction built or account already onboarded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OnboardBuildResponse'
        '400':
          description: Could not build the onboarding transaction.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: build_failed
        '401':
          description: Invalid or missing API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '502':
          description: Facilitator could not reach Stellar Horizon.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    OnboardBuildRequest:
      type: object
      required:
        - publicKey
        - chain
      properties:
        publicKey:
          allOf:
            - $ref: '#/components/schemas/StellarPublicKey'
          description: G-address of the account to onboard.
        chain:
          $ref: '#/components/schemas/FacilitatorChain'
    OnboardBuildResponse:
      type: object
      properties:
        ok:
          type: boolean
          description: Optional status flag.
        unsignedTxXdr:
          type: string
          description: >-
            Unsigned onboarding transaction as base64 XDR. Present when the
            account is not yet fully onboarded. Sign with the user's key and
            submit via `POST /stellar/onboard/submit`.
        nothingToDo:
          type: boolean
          description: >-
            When `true`, the account is already onboarded. No XDR needs to be
            signed or submitted.
      description: Response from `POST /stellar/onboard/build`.
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: >-
            Machine-readable error code. SDK error codes (e.g.
            `RELAYER_REJECTED`, `SESSION_POLICY_VIOLATION`) or raw facilitator
            codes (e.g. `auth_expired`, `simulation_failed`) depending on
            context.
        message:
          type: string
          description: >-
            Optional human-readable detail. Never log raw upstream messages -
            they may contain addresses or sensitive information.
        details:
          type: object
          description: >-
            Optional structured validation errors (present on BFF-level schema
            failures).
      description: >-
        Error body returned on non-2xx responses. The `error` field maps to a
        `BuckspayErrorCode` or a raw facilitator error string (see
        `mapFacilitatorError` in `@buckspay/relayer`).
    StellarPublicKey:
      type: string
      pattern: ^G[A-Z2-7]{55}$
      description: Stellar classic public key (G-address, 56-character StrKey).
    FacilitatorChain:
      type: string
      enum:
        - stellar-testnet
        - stellar-pubnet
      description: Stellar network identifier used in facilitator requests.
  securitySchemes:
    FacilitatorApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Server-held API key. Injected by the BFF (`createRelayRoute` /
        `createSignerProxyRoute` from `@buckspay/nextjs`). This key must only
        appear in server-side code and must never be shipped to a browser
        bundle.

````