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

# Build a user operation

> Builds an ERC-4337 user operation (EntryPoint v0.6) for an Account Abstraction
client from one or more calls, which the smart account executes in order.
Returns the user operation and the hash to sign. Sign `userOpHash` with the
Enclave MPC API `POST /v1/raw/sign/SECP256K1` (or `rawSign` in the SDKs), then
submit both with `broadcast-user-operation`.

Gas is sponsored when the environment has gas sponsorship configured for the
chain; otherwise `paymasterAndData` is `0x` and the smart account pays for gas.
The environment's transaction policies are evaluated on every call.




## OpenAPI

````yaml /openapi/client-api.yaml post /clients/me/chains/{chain}/assets/send/build-user-operation
openapi: 3.1.0
info:
  title: Portal Client API
  version: '3.0'
  description: >
    The Portal Client API provides endpoints for managing wallets, building
    transactions,

    and interacting with blockchain networks. All endpoints require
    authentication via a

    Client API Key or Client Session Token (CST) passed as a Bearer token.


    ## Base URL

    `https://api.portalhq.io/api/v3`


    ## Authentication

    Include your Client API Key or Client Session Token as a Bearer token in the

    `Authorization` header of every request.


    ## Chain ID Format

    Chain parameters use either friendly names (e.g. `ethereum`, `solana`) or
    CAIP-2 format

    (e.g. `eip155:1`, `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`). When using
    CAIP-2 format

    in URLs, ensure the colon is URI-encoded (`%3A`).
servers:
  - url: https://api.portalhq.io/api/v3
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Clients
    description: Core client management endpoints
  - name: Wallet
    description: >-
      Read wallet state — balances, NFTs, transaction history, capabilities, and
      transaction details
  - name: Transactions
    description: Build, broadcast, and evaluate blockchain transactions
  - name: Funding
    description: Fund wallets with testnet tokens
  - name: Wallet Shares
    description: Manage signing and backup share pairs
  - name: Delegations
    description: Manage token approvals, revocations, and delegated transfers
  - name: Session Keys
    description: Manage EIP-7702 session keys for smart accounts
  - name: 0x
    description: Token swap endpoints powered by the 0x protocol
  - name: Yield.xyz
    description: Yield opportunities and staking actions powered by Yield.xyz
  - name: Yield.xyz Borrow
    description: >-
      Supply collateral, borrow, repay and withdraw from lending markets (Aave
      V3, Morpho Blue, SparkLend, Lista) powered by Yield.xyz Borrow
  - name: Yield.xyz Perps
    description: >-
      Trade perpetual futures — open/close leveraged positions, manage
      stop-loss/take-profit, and fund/withdraw a trading account — powered by
      Yield.xyz Perps
  - name: Li.Fi
    description: Cross-chain swaps and bridging powered by Li.Fi
  - name: Blockaid
    description: Transaction and address security scanning powered by Blockaid
  - name: Hypernative
    description: >-
      Transaction, address, token, and NFT security scanning powered by
      Hypernative
  - name: Noah
    description: KYC onboarding, payins, and payouts powered by Noah
  - name: Meld
    description: Buy and sell crypto with fiat through aggregated providers powered by Meld
  - name: Due
    description: Payins, payouts, virtual accounts, and FX powered by Due
  - name: EIP-7702
    description: EIP-7702 account type detection and authorization management
  - name: Deprecated
    description: >-
      Legacy endpoints scheduled for removal. Use the newer equivalents listed
      in each endpoint's description.
paths:
  /clients/me/chains/{chain}/assets/send/build-user-operation:
    post:
      tags:
        - Transactions
      summary: Build a user operation
      description: >
        Builds an ERC-4337 user operation (EntryPoint v0.6) for an Account
        Abstraction

        client from one or more calls, which the smart account executes in
        order.

        Returns the user operation and the hash to sign. Sign `userOpHash` with
        the

        Enclave MPC API `POST /v1/raw/sign/SECP256K1` (or `rawSign` in the
        SDKs), then

        submit both with `broadcast-user-operation`.


        Gas is sponsored when the environment has gas sponsorship configured for
        the

        chain; otherwise `paymasterAndData` is `0x` and the smart account pays
        for gas.

        The environment's transaction policies are evaluated on every call.
      operationId: buildUserOperation
      parameters:
        - $ref: '#/components/parameters/chain'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - calls
              properties:
                calls:
                  type: array
                  minItems: 1
                  description: The calls the smart account makes, in order.
                  items:
                    type: object
                    required:
                      - to
                    properties:
                      to:
                        type: string
                        description: The address to call.
                      value:
                        type: string
                        description: >-
                          Native value in wei, as a decimal or hex string.
                          Defaults to `0`.
                      data:
                        type: string
                        description: Hex calldata. Defaults to `0x`.
            example:
              calls:
                - to: '0xd2b58253741d22bc530b214f8fe81bf1a78a72b1'
                  value: '0'
                - to: '0x9533731C8224CEc3E53D76B72b590D347d9257eC'
                  value: '0'
                  data: 0x
      responses:
        '200':
          description: User operation built
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      userOperation:
                        type: string
                        description: >-
                          The user operation as a JSON string. Pass it unchanged
                          to `broadcast-user-operation`.
                      userOpHash:
                        type: string
                        description: The user operation hash to sign.
                  metadata:
                    type: object
                    properties:
                      chainId:
                        type: string
                      totalGas:
                        type: string
                        description: >-
                          Gas units the user operation is bounded by (sum of its
                          gas limits), as a decimal string.
                      maxFeePerGas:
                        type: string
                        description: >-
                          Maximum price per gas unit in wei, as a decimal
                          string.
                      estimatedGasCostWei:
                        type: string
                        description: >-
                          `totalGas` times `maxFeePerGas`: the most the user
                          operation can cost in wei when the smart account pays
                          for gas.
              example:
                data:
                  userOperation: >-
                    {"sender":"0xF86e3fAe8443e4494a689fcDd4C8e6C76c1b2C96","nonce":"0x5","initCode":"0x","callData":"0x34fcd5be...","paymasterAndData":"0x","signature":"0x00000000ffff...","maxFeePerGas":"0x58556415","maxPriorityFeePerGas":"0x15d0ea4","callGasLimit":"0x3f9b","verificationGasLimit":"0x13d75","preVerificationGas":"0xc808"}
                  userOpHash: >-
                    0xba1f6f1fe76b7a39d660bd02f54a3de5eae99ab413a95246e394c06786003847
                metadata:
                  chainId: eip155:11155111
                  totalGas: '148760'
                  maxFeePerGas: '1481991189'
                  estimatedGasCostWei: '220461009275640'
        '400':
          description: >
            Bad request. Common causes:

            - The client does not have Account Abstraction enabled

            - `calls` is missing or empty, or a call has an invalid `to`,
            `value` or `data`

            - The chain is not an EVM chain
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: >-
                  Account Abstraction is not enabled, contact support to enable
                  it
        '401':
          description: Unauthorized - invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: A transaction policy blocked one of the calls.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  policyViolation:
                    type: object
                    properties:
                      policyId:
                        type: string
                      policyName:
                        type: string
                      reason:
                        type: string
                      ruleId:
                        type: string
              example:
                error: 'Policy violation: amount exceeds limit (Max transfer)'
                policyViolation:
                  policyId: policyId
                  policyName: Max transfer
                  reason: amount exceeds limit (Max transfer)
                  ruleId: ruleId
components:
  parameters:
    chain:
      name: chain
      in: path
      required: true
      description: >
        The blockchain chain identifier. Use either a friendly name or CAIP-2
        format.

        When using CAIP-2 format in URLs, ensure the colon (`:`) is URI-encoded
        as `%3A`.


        **Supported chains:**

        - `ethereum` (`eip155:1`)

        - `sepolia` (`eip155:11155111`)

        - `base` (`eip155:8453`)

        - `base-sepolia` (`eip155:84532`)

        - `polygon` (`eip155:137`)

        - `polygon-mumbai` (`eip155:80001`)

        - `celo` (`eip155:42220`)

        - `celo-alfajores` (`eip155:44787`)

        - `monad` (`eip155:143`)

        - `monad-testnet` (`eip155:10143`)

        - `solana` (`solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`)

        - `solana-devnet` (`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`)

        - `tron` (`tron:mainnet`)

        - `tron-nile` (`tron:nile`)

        - `tron-shasta` (`tron:shasta`)

        - `stellar` (`stellar:pubnet`)

        - `stellar-testnet` (`stellar:testnet`)

        - `bitcoin-segwit` (`bip122:000000000019d6689c085ae165831e93-p2wpkh`)

        - `bitcoin-segwit-testnet`
        (`bip122:000000000933ea01ad0ee984209779ba-p2wpkh`)

        - `bitcoin-p2wpkh` (`bip122:000000000019d6689c085ae165831e93-p2wpkh`)

        - `bitcoin-p2wpkh-testnet`
        (`bip122:000000000933ea01ad0ee984209779ba-p2wpkh`)
      schema:
        type: string
      examples:
        ethereum:
          value: ethereum
          summary: Ethereum mainnet (friendly name)
        eip155:
          value: eip155:1
          summary: Ethereum mainnet (CAIP-2)
        solana:
          value: solana
          summary: Solana mainnet (friendly name)
        bitcoin:
          value: bitcoin-segwit
          summary: Bitcoin segwit (friendly name)
  schemas:
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message describing what went wrong
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Client API Key or Client Session Token (CST). Pass as a Bearer token in
        the

        Authorization header.

````