# Create buy offer

This endpoint is designed for creating an transaction to purchase an ordinal listed for sale on the marketplace.\
\
**Platform Cost:** \
A platform fee is applied only when an ordinal is sold. It is not charged for listing an ordinal. The current fee is 1% of sale amount charged to the seller.

Upon usage, it generates a Partially Signed Bitcoin Transaction (PSBT) encoded in base64. This PSBT must be signed by the individual intending to buy the ordinal.

Here's an example of executing a purchase transaction with Xverse wallet:<br>

```javascript
      
      // XVerse Wallet example of creating a signing request 
      // when buying an Ordinal

      // Create the purchase PSBT by calling /marketplace/create-offer
      const { data } = await axios({
        method: 'post'
        url: 'https://api.ordinalsbot.com/marketplace/create-offer',
        data: {
          ordinalId: id,
          buyerPaymentAddress: paymentAddress,
          buyerOrdinalAddress: ordinalsAddress,
          buyerPaymentPublicKey: paymentPublicKey
        },
        headers: {
        'x-api-key': API_KEY,
      });

      // returned response has a base64 encoded psbt to sign and an array of input
      // indices which the buyer needs to sign with the payment address wallet
      const buyerInput = {
        address: paymentAddress, // Buyer's payment wallet address
        signingIndexes: data.buyerInputIndices
      };

      // When using XVerse Wallet
      // Create the payload for signing the buyer transaction
      const payload = {
        network: { type: "Mainnet" },
        message: "Sign Buyer Transaction",
        psbtBase64: data.psbt,
        broadcast: false,
        inputsToSign: [buyerInput],
      };

      // Make signing request
      await signTransaction({
        payload,
        onFinish: async (response) => {
          try {
            // Here make a call to /submit-offer
            // Things to do after successful signing
          } catch (Error) {
            // error handling
          }
        },
        onCancel: () => { // User cancelled signing request }
      });

```

### `POST` Buy an ordinal

## Buy a listed ordinal

<mark style="color:green;">`POST`</mark> `https://api.ordinalsbot.com/marketplace/create-offer`

API Key is required in the header:

`headers: { 'x-api-key': '<YOUR_API_KEY>', ...otherHeaders }`

#### Request Body

| Name                                                    | Type   | Description                                                                                                                                                               |
| ------------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ordinalId<mark style="color:red;">\*</mark>             | String | Id of the ordinal to buy.                                                                                                                                                 |
| buyerPaymentAddress<mark style="color:red;">\*</mark>   | String | Buyer's payment wallet address. The buyer will need to pay the cost of the transaction from UTXOs belonging to this address.                                              |
| buyerPaymentPublicKey<mark style="color:red;">\*</mark> | String | Public Key for buyer's payment wallet address.                                                                                                                            |
| buyerOrdinalAddress<mark style="color:red;">\*</mark>   | String | Buyer's Ordinal wallet address. The purchased Ordinal will be transferred to this address.                                                                                |
| feeRateTier                                             | String | <p>Transaction fee rate should be one of the following. Defaults to fastestFee if not specified:<br><br>fastestFee<br>halfHourFee<br>hourFee<br>minimumFee</p><p><br></p> |

{% tabs %}
{% tab title="200: OK " %}

```json

{
    "psbt": "cHNidP8BA............z730AAAAAAAAAAA==",
    "buyerInputIndices": [ 0, 1, 3, 4, 5, 6 ]
}

```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```json
{
    status: 'error',
    error: 'error reason'
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ordinalsbot.com/marketplace-1/create-buy-offer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
