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

# Approve order fill

> Approve token spending via EIP-2612 permit for SX Bet order execution.

<Note>
  If you don't wish to do this programmatically, you can simply go to [sx.bet](https://sx.bet) (or [toronto.sx.bet](https://toronto.sx.bet) for testnet), place a test bet with the account and token you'll be using, and you will be good to go.

  If you want to do it programmatically, see the code sample below.
</Note>

This endpoint approves the specified `value` to be spent by `spender` on behalf of `owner` for token transfers that occur as part of the [Filling orders](/api-reference/post-fill-order) flow according to Ethereum's [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612) Permit Extension. Note that `deadline` field here is only used during signature verification and that the `value` set will be the spender's allowance until changed or revoked.


## OpenAPI

````yaml POST /orders/approve
openapi: 3.0.1
info:
  title: SX Bet API
  version: 1.0.0
  description: >-
    REST API for the SX Bet decentralized sports betting exchange. Retrieve
    sports data, markets, and orderbook information. Post, cancel, and fill
    orders with signed payloads.


    Base URLs:

    - **Mainnet**: `https://api.sx.bet`

    - **Testnet**: `https://api.toronto.sx.bet`
servers:
  - url: https://api.sx.bet
    description: Mainnet (SX Network, chainId 4162)
  - url: https://api.toronto.sx.bet
    description: Testnet (Toronto, chainId 79479957)
security: []
tags:
  - name: Connection
    description: Server metadata and heartbeat management
  - name: Sports Data
    description: Sports, leagues, teams, fixtures, and live scores
  - name: Markets
    description: Active, specific, and popular betting markets
  - name: Trades
    description: Matched trades and portfolio history
  - name: Orders
    description: Orderbook queries, posting, cancelling, and filling orders
paths:
  /orders/approve:
    post:
      tags:
        - Orders
      summary: Approve betting (EIP-2612 Permit)
      operationId: approveBetting
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - owner
                - spender
                - tokenAddress
                - value
                - deadline
                - signature
              properties:
                owner:
                  type: string
                  description: >-
                    Address of the taker granting approval to TokenTransferProxy
                    for filling orders on their behalf
                spender:
                  type: string
                  description: >-
                    The address of the account which will be able to spend token
                    amounts on behalf of the owner. In this case, the spender
                    should be TokenTransferProxy address
                tokenAddress:
                  type: string
                  description: The token address to grant approval for
                value:
                  type: string
                  description: The token amount to grant approval for, in Ethereum units
                deadline:
                  type: integer
                  description: >-
                    The deadline as a UNIX timestamp format used in signature
                    verification
                signature:
                  type: string
                  description: >-
                    Your wallet signature over the payload. See the example of
                    how to compute this.
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    description: '`success` or `failure` if the request succeeded or not'
                  data:
                    type: object
                    properties:
                      hash:
                        type: string
                        nullable: true
                        description: >-
                          The transaction hash of the approval, or `null` if the
                          allowance was already set
              example:
                status: success
                data:
                  hash: >-
                    0x840763ae29b7a6adfa0e315afa47be30cdebd5b793d179dc07dc8fc4f0034965
      x-codeSamples:
        - lang: javascript
          label: EIP-2612 Permit
          source: >-
            import { Contract, JsonRpcProvider, MaxUint256, Wallet } from
            "ethers";


            async function approveOrderFill() {
              const privateKey = process.env.SX_PRIVATE_KEY;
              const tokenAddress = process.env.TOKEN_ADDRESS;

              // get the following from https://api.sx.bet/metadata
              const tokenTransferProxyAddress = process.env.TOKEN_TRANSFER_PROXY_ADDRESS;
              const chainId = Number(process.env.CHAIN_ID); // Mainnet — use 79479957 for testnet

              const wallet = new Wallet(
                privateKey,
                new JsonRpcProvider(process.env.RPC_URL) // find this under the 'references' section
              );

              const tokenContract = new Contract(
                tokenAddress,
                [
                  {
                    inputs: [
                      { internalType: "address", name: "usr", type: "address" },
                      { internalType: "uint256", name: "wad", type: "uint256" },
                    ],
                    name: "approve",
                    outputs: [{ internalType: "bool", name: "", type: "bool" }],
                    stateMutability: "nonpayable",
                    type: "function",
                  },
                  {
                    inputs: [{ internalType: "address", name: "owner", type: "address" }],
                    name: "nonces",
                    outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
                    stateMutability: "view",
                    type: "function",
                  },
                  {
                    inputs: [],
                    name: "name",
                    outputs: [{ internalType: "string", name: "", type: "string" }],
                    stateMutability: "view",
                    type: "function",
                  },
                ],
                wallet
              );

              const nonce = await tokenContract.nonces(wallet.address);
              const tokenName = await tokenContract.name();

              const domain = {
                name: tokenName,
                version: "1",
                chainId,
                verifyingContract: tokenAddress,
              };

              const types = {
                Permit: [
                  { name: "owner", type: "address" },
                  { name: "spender", type: "address" },
                  { name: "value", type: "uint256" },
                  { name: "nonce", type: "uint256" },
                  { name: "deadline", type: "uint256" },
                ],
              };

              const deadline = Math.floor(Date.now() / 1000) + 7200; // 2 hours

              const value = {
                owner: wallet.address,
                spender: tokenTransferProxyAddress,
                value: MaxUint256,
                nonce,
                deadline,
              };

              const approveProxySignature = await wallet.signTypedData(domain, types, value);

              const apiPayload = {
                owner: wallet.address,
                spender: tokenTransferProxyAddress,
                tokenAddress,
                value: MaxUint256.toString(),
                deadline,
                signature: approveProxySignature,
              };

              const response = await fetch("https://api.sx.bet/orders/approve", { // Mainnet — use https://api.toronto.sx.bet for testnet
                method: "POST",
                body: JSON.stringify(apiPayload),
                headers: { "Content-Type": "application/json" },
              });
            }

````