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

# Quickstart

> Sell a covered call on Ethereum: find an instrument, prepare the wallet, get a firm quote, and send the settlement transaction.

This guide shows how to sell a covered WETH call and collect the premium. At the end, the wallet holds the receipt tokens and the USDC premium, and the trade shows as an open position.

> [!WARNING]
>
> There is no testnet environment. To test your integration, use small amounts on mainnet.

## Before you begin

* Get an API key with options taker access. [Contact Us](https://form.typeform.com/to/F8hEoBYi?utm_source=options_docs).
* Use a wallet that holds the WETH collateral and ETH for gas. The wallet must hold no option tokens of the instrument that you sell.
* Have the URL of an Ethereum RPC node.
* Install the Python packages: `pip install httpx web3`.
* Set the environment variables `BEBOP_API_KEY`, `ETH_RPC_URL`, and `PRIVATE_KEY`. Do not put the private key in the source code.

The examples on this page and in the guides use these settings:

```python theme={null}
import os

import httpx
from eth_account import Account
from web3 import Web3

API = "https://api.bebop.xyz/options/ethereum/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['BEBOP_API_KEY']}"}
SETTLEMENT = Web3.to_checksum_address("0xbbbbbBB520d69a9775E85b458C58c648259FAD5F")
WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

w3 = Web3(Web3.HTTPProvider(os.environ["ETH_RPC_URL"]))
account = Account.from_key(os.environ["PRIVATE_KEY"])


def send(tx: dict) -> str:
    tx = {
        **tx,
        "from": account.address,
        "chainId": 1,
        "nonce": w3.eth.get_transaction_count(account.address),
    }
    if "maxFeePerGas" not in tx and "gasPrice" not in tx:
        tx["gasPrice"] = w3.eth.gas_price
    tx["gas"] = w3.eth.estimate_gas(tx) * 12 // 10
    signed = account.sign_transaction(tx)
    tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
    receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=180)
    if receipt["status"] != 1:
        raise RuntimeError(f"transaction reverted: {tx_hash.hex()}")
    return tx_hash.hex()
```

**1. Find an instrument**

List the active WETH calls and choose one where `canSell` is `true`. The `instrument` field is the option token address.

The Python example chooses the nearest expiry and its highest strike. Change the selection to the strike and the expiry that you want to sell.

```bash bash theme={null}
curl --get "https://api.bebop.xyz/options/ethereum/v1/instruments" \
  --data-urlencode "underlying=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" \
  --data-urlencode "option_type=call" \
  --data-urlencode "limit=200"
```

```python python theme={null}
page = httpx.get(
    f"{API}/instruments",
    params={"underlying": WETH, "option_type": "call", "limit": 200},
).json()
sellable = [i for i in page["instruments"] if i["canSell"]]
expiration = min(i["expiration"] for i in sellable)
instrument = max(
    (i for i in sellable if i["expiration"] == expiration),
    key=lambda i: float(i["strike"]),
)
print(instrument["symbol"], instrument["strike"], instrument["expiration"])
```

The output is similar to:

```text theme={null}
OPTE-C-WETH-USDC-2500-2026-11-27 2500 1795766400
```

If `nextCursor` is not `null`, more instruments are on the next page. See [List instruments](https://docs.bebop.xyz/options-api/reference.md#list-instruments).

**2. Set the amount**

The amount is in raw collateral units. A WETH call uses 18 decimals, so 0.01 WETH is `10000000000000000`.

```python theme={null}
amount = 10_000_000_000_000_000  # 0.01 WETH
```

For a put, the amount is in USDC (6 decimals): the strike times the underlying amount. See [Amounts](https://docs.bebop.xyz/options-api/reference.md#amounts).

**3. Approve the collateral to the Greek Factory**

The Greek Factory pulls the collateral when the trade settles. Read its address from the `factory` field of the instrument.

```python theme={null}
ERC20_ABI = [
    {"name": "allowance", "type": "function", "stateMutability": "view",
     "inputs": [{"name": "owner", "type": "address"}, {"name": "spender", "type": "address"}],
     "outputs": [{"name": "", "type": "uint256"}]},
    {"name": "approve", "type": "function", "stateMutability": "nonpayable",
     "inputs": [{"name": "spender", "type": "address"}, {"name": "amount", "type": "uint256"}],
     "outputs": [{"name": "", "type": "bool"}]},
]

factory = Web3.to_checksum_address(instrument["factory"])
collateral = w3.eth.contract(Web3.to_checksum_address(instrument["collateral"]), abi=ERC20_ABI)

if collateral.functions.allowance(account.address, factory).call() < amount:
    send(collateral.functions.approve(factory, amount).build_transaction({"from": account.address}))
```

**4. Grant the settlement contract the open permission**

> [!WARNING]
>
> This permission lets the settlement contract transfer and mint option tokens for the wallet, for every instrument of this Greek Factory. It is not limited to an amount.

Add mask `3` (`TRANSFER | MINT`) for the settlement contract. Use `addPermissions`. `setPermissions` replaces the complete mask.

```python theme={null}
FACTORY_ABI = [
    {"name": "permissions", "type": "function", "stateMutability": "view",
     "inputs": [{"name": "account", "type": "address"}, {"name": "operator", "type": "address"}],
     "outputs": [{"name": "", "type": "uint256"}]},
    {"name": "addPermissions", "type": "function", "stateMutability": "nonpayable",
     "inputs": [{"name": "operator", "type": "address"}, {"name": "mask", "type": "uint256"}],
     "outputs": []},
]
OPEN_MASK = 3

greek_factory = w3.eth.contract(factory, abi=FACTORY_ABI)
granted = greek_factory.functions.permissions(account.address, SETTLEMENT).call()
if granted & OPEN_MASK != OPEN_MASK:
    send(greek_factory.functions.addPermissions(SETTLEMENT, OPEN_MASK).build_transaction({"from": account.address}))
```

**5. Request a quote**

Request a sell-to-open quote with `validate=true`. Bebop then also checks the wallet balance, allowance, and permission, and lists any problem in `issues`.

```bash bash theme={null}
curl --get "https://api.bebop.xyz/options/ethereum/v1/quote" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  --data-urlencode "instrument=0xOPTION_TOKEN" \
  --data-urlencode "amount=10000000000000000" \
  --data-urlencode "taker_address=0xYOUR_WALLET" \
  --data-urlencode "validate=true"
```

```python python theme={null}
response = httpx.get(
    f"{API}/quote",
    headers=HEADERS,
    params={
        "instrument": instrument["instrument"],
        "amount": str(amount),
        "taker_address": account.address,
        "validate": "true",
    },
)
response.raise_for_status()
quote = response.json()
if quote["issues"]:
    raise RuntimeError(f"wallet not ready: {quote['issues']}")
print(quote["premium"], quote["fee"], quote["expiry"])
```

The output is similar to:

```text theme={null}
643000 2000 1793300460
```

`premium` is the USDC that the wallet receives, after the Bebop fee, in raw units (6 decimals). In this example, the wallet receives 0.643 USDC. `fee` is already deducted from `premium`.

**6. Send the transaction**

Send `tx` from the wallet in `taker_address`. The quote is firm until `expiry`, a Unix timestamp in seconds. Do not change `tx.data`.

```python theme={null}
tx_hash = send({
    "to": Web3.to_checksum_address(quote["tx"]["to"]),
    "data": quote["tx"]["data"],
    "value": int(quote["tx"]["value"]),
})
print(tx_hash)
```

If `expiry` passes before you send, request a new quote.

**7. Verify the position**

Read the position with the `positionId` from the quote. Bebop returns `404` until it indexes the transaction, so try again while the response is `404`.

```python theme={null}
import time

for _ in range(30):
    response = httpx.get(f"{API}/positions/{quote['positionId']}", headers=HEADERS)
    if response.status_code != 404:
        break
    time.sleep(2)
response.raise_for_status()
position = response.json()
print(position["status"], position["remainingAmount"], position["premiumReceived"])
```

The output is similar to:

```text theme={null}
open 10000000000000000 643000
```

The wallet now holds 0.01 RT of the instrument, and its WETH balance is 0.01 lower.

## If it does not work

| Symptom | Cause | Correction |
| - | - | - |
| `401` `Unauthorized` | The API key is missing or not valid. | Send the header `Authorization: Bearer <API key>`. |
| `403` `Forbidden` | The API key has no options taker access. | [Contact support](https://docs.bebop.xyz/support.md). |
| `issues` contains `missing_factory_permissions` | The settlement contract does not have mask `3`. | Do the permission step again. |
| `issues` contains `insufficient_collateral_allowance` | The Greek Factory allowance is less than `amount`. | Do the approval step again. |
| `409` `ExistingOptionBalance` | The wallet holds option tokens of this instrument. | Move them out, or use another wallet. |
| `400` `MinNotional` | `amount` is below the minimum. | Increase `amount`. See [Limits](https://docs.bebop.xyz/options-api/reference.md#limits). |
| `400` `MaxSize` | `amount` is above the maximum size of every eligible maker. | Use an amount at or below `maxUnderlyingAmount` of the instrument. |
| `503` `NoValidMakerQuote` | No maker returned a valid quote. | Try again later, or try another instrument. |
| The transaction reverts | The quote expired, or the wallet changed after the quote. | Request a new quote with `validate=true`. |

## Related

* [Close a position](https://docs.bebop.xyz/options-api/guides/close-a-position.md)
* [How options settle](https://docs.bebop.xyz/options-api/how-options-settle.md)
* [Reference](https://docs.bebop.xyz/options-api/reference.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.