# Provider API Methods

Using the [Sats Connect methods](https://docs.xverse.app/sats-connect-v1) is the easiest way to format the request strings that get passed down to our actual provider method parameters. Below is all of the methods we support directly on the provider.

## Provider Methods

### `Connect`

Prompts a connection to a user's Magic Eden Wallet account.

#### Params

Without using Sats Connect, you could encode your request payload like below. However, [getAddress](https://docs.xverse.app/sats-connect-v1/methods/getaddress) takes care of this for you

```typescript
import * as jsontokens from 'jsontokens'

enum AddressPurposes {
  PAYMENT = 'payment',
  ORDINALS = 'ordinals',
}

const payload = {
  purposes: [AddressPurposes.PAYMENT, AddressPurposes.ORDINALS],
}
const request = jsontokens.createUnsecuredToken(payload)
```

| Property  | Type     | Description              |
| --------- | -------- | ------------------------ |
| `request` | `string` | The json encoded payload |

#### Response

| Property                     | Type    | Description                                     |
| ---------------------------- | ------- | ----------------------------------------------- |
| `Promise<getAddressRespose>` | `array` | Array of the connected user’s `Address` objects |

#### `Address` Response Properties

| Property    | Type                             | Description                                                                                                            |
| ----------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `address`   | `string`                         | The user's BTC address                                                                                                 |
| `publicKey` | `string`                         | A hex string representing the full publicKey of your BTC account. Your address is shortened from this                  |
| `purpose`   | `enum - 'payment' \| 'ordinals'` | The purpose of the address is used to indicate whether this address is preferrably used for payments or ordinals/runes |

### `signMessage`

Prompts to sign a message with the user's connected Magic Eden Wallet account

#### Params

Without using Sats Connect, you could encode your request payload like below. However, [signMessage](https://docs.xverse.app/sats-connect-v1/methods/signmessage) takes care of this for you

```typescript
import * as jsontokens from 'jsontokens'

export interface SignMessagePayload {
  address: string
  message: string
  protocol?: string
}

const payload = {
  'bc1qcdmvsc8qqk8sr2st3mttu6fsmfrjzh5xrf4dch',
  'Welcome to my dApp!',
}
const request = jsontokens.createUnsecuredToken(payload)
```

| Property  | Type     | Description              |
| --------- | -------- | ------------------------ |
| `request` | `string` | The json encoded payload |

Where protocol accepts either `'BIP322'` or `'ECDSA'` and defaults to the former if no value is provided. By default all signatures will follow the up to date [bip322](https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki) standard, but certain apps require legacy signing. Passing in `'ECDSA'` will ensure legacy signing only for segwit/payment addresses.

#### Response

| Property          | Type     | Description                     |
| ----------------- | -------- | ------------------------------- |
| `Promise<string>` | `string` | String containing the signature |

### `signTransaction`

Prompts to sign a PSBT with the user's connected Magic Eden Wallet account.

#### Params

Without using Sats Connect, you could encode your request payload like below. However, [signTransaction](https://docs.xverse.app/sats-connect-v1/methods/signtransaction) takes care of this for you

```typescript
import * as jsontokens from 'jsontokens'

const payload: any = {
  network: {
    type: 'Mainnet',
  },
  message: 'wow',
  psbtBase64: `cHNidP8BAIkCAAAAAcdT+1joxn7quCzc5RHnqjiUO3odlGn2dznH7/QY4uwlAgAAAAD/////AugDAAAAAAAAIgAgQw4WXibgytGq1y25JPXvYiECxZCpUo6L31w+KfQtgk2HmQAAAAAAACIAIEMOFl4m4MrRqtctuST172IhAsWQqVKOi99cPin0LYJNAAAAAAABASv4pwAAAAAAACIAIEMOFl4m4MrRqtctuST172IhAsWQqVKOi99cPin0LYJNAQMEggAAAAEFR1IhA9/z2Wg/zWhuy2Wtm8KZC+NuwqQzhN3PG+L5GrmOOecFIQP3thdmUgZQrE2gZFZt1red4El15NcoNxCj6syNnj19i1KuAAAA`,
  broadcast: false,
  inputsToSign: [
    {
      address,
      signingIndexes: [1],
    },
  ],
}

if (sigHash) {
  payload.inputsToSign[0].sigHash = sigHash
}

const request = jsontokens.createUnsecuredToken(payload)
```

| Property  | Type     | Description              |
| --------- | -------- | ------------------------ |
| `request` | `string` | The json encoded payload |

#### Response

| Property                           | Type     | Description                              |
| ---------------------------------- | -------- | ---------------------------------------- |
| `Promise<SignTransactionResponse>` | `object` | The returned psbt in base64 and the txId |

#### `SignTransactionResponse` Response Properties

| Property     | Type     | Description                           |
| ------------ | -------- | ------------------------------------- |
| `psbtBase64` | `string` | The base64 encoded psbt string        |
| `txId`       | `string` | an optional transaction Id on success |

### `sendBtcTransaction`

Prompts to send BTC from the user's connected Magic Eden Wallet account.

#### Params

Without using Sats Connect, you could encode your request payload like below. However, [sendBtcTransaction](https://docs.xverse.app/sats-connect-v1/methods/sendbtctransaction) takes care of this for you

```typescript
import * as jsontokens from 'jsontokens'

const payload: any = {
  recipients: [
    {
      // recipient BTC address
      'bc1qcdmvsc8qqk8sr2st3mttu6fsmfrjzh5xrf4dch',
      amountSats: `3000`,
    },
  ],
  senderAddress: address,
}

const request = jsontokens.createUnsecuredToken(payload)
```

| Property  | Type     | Description              |
| --------- | -------- | ------------------------ |
| `request` | `string` | The json encoded payload |

#### Response

| Property          | Type     | Description                          |
| ----------------- | -------- | ------------------------------------ |
| `Promise<string>` | `string` | String containing the transaction Id |

### `signMultipleTransactions (custom)`

Prompts to sign multiple PSBTs under one approval with the user's connected Magic Eden Wallet account. *This is currently a private wallet method that is whitelisted to the magic eden marketplace domain*

#### Params

This is a custom feature of the Magic Eden Wallet and thus cannot be invoked with sats-connect, as you have the choice to do with the other provider methods. Rather, you can call this method with a similar request string as `signTransaction`

```typescript
import * as jsontokens from 'jsontokens'

const payload: any = {
  network: {
    type: 'Mainnet',
  },
  message: 'Sign Multiple Transactions dummy message',
  psbts: [
    {
      psbtBase64:
        'cHNidP8BAIkCAAAAAcdT+1joxn7quCzc5RHnqjiUO3odlGn2dznH7/QY4uwlAgAAAAD/////AugDAAAAAAAAIgAgQw4WXibgytGq1y25JPXvYiECxZCpUo6L31w+KfQtgk2HmQAAAAAAACIAIEMOFl4m4MrRqtctuST172IhAsWQqVKOi99cPin0LYJNAAAAAAABASv4pwAAAAAAACIAIEMOFl4m4MrRqtctuST172IhAsWQqVKOi99cPin0LYJNAQMEggAAAAEFR1IhA9/z2Wg/zWhuy2Wtm8KZC+NuwqQzhN3PG+L5GrmOOecFIQP3thdmUgZQrE2gZFZt1red4El15NcoNxCj6syNnj19i1KuAAAA',
      inputsToSign: [
        {
          address,
          signingIndexes: [1],
          sigHash: 0x82,
        },
      ],
    },
    {
      psbtBase64:
        'cHNidP8BAFMCAAAAAYZhHMQ1Mjf1j3mtKvSHg128Nird1Lz62NyvyCF+xvG/AQAAAAD/////ATCmBwAAAAAAF6kUoaCqiRUca/0Ct3DHsaLnYllpTLiHAAAAAAj8Am1lA3NpZ0ALaP+AC+tlBfBS6QdQEv1c8blRxYKVxCdL/MEmw1DMoQEWySlU3ejsBZ+Nh+IjpAWUWYyOSdmpJgdUmPfvolpdC/wCbWUGc2lnZXhwCEJ5Hs28doAAAAEBKyICAAAAAAAAIlEg39xRNMrlIZlVJKDvuPjChZEYR0U314t+SXHBxHd08SMBAwSDAAAAARcgSuLJW58BUTAvZxKpS0E4abC/u9pAXsb/SeTXM/CrP/MADvwCbWUJcHJpY2VTYXRzBjUwMDAwMAA=',
      inputsToSign: [
        {
          address: addressOrdinals,
          signingIndexes: [0],
          sigHash: 0x83,
        },
      ],
    },
  ],
}

const request = jsontokens.createUnsecuredToken(payload)
```

You can then pass this stringified request into the provider method like so: `window.magicEden.bitcoin.signMultipleTransactions(request)`<br>

| Property  | Type     | Description              |
| --------- | -------- | ------------------------ |
| `request` | `string` | The json encoded payload |

#### Response

| Property                             | Type     | Description                                       |
| ------------------------------------ | -------- | ------------------------------------------------- |
| `Promise<SignTransactionResponse[]>` | `object` | Array of the returned psbt in base64 and the txId |

#### `SignTransactionResponse` Response Properties

| Property     | Type     | Description                           |
| ------------ | -------- | ------------------------------------- |
| `psbtBase64` | `string` | The base64 encoded psbt string        |
| `txId`       | `string` | an optional transaction Id on success |


---

# 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-wallet.magiceden.io/bitcoin/provider-api-methods.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.
