> For the complete documentation index, see [llms.txt](https://brink.gitbook.io/brink/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brink.gitbook.io/brink/developer-guides/api.md).

# API

## Get API Information

<mark style="color:blue;">`GET`</mark> `https://api.brink.trade/info`

This endpoint returns Brink API information, such as the version of the API.

{% tabs %}
{% tab title="200 Brink API information is returned." %}

```
{    "service": "@brinkninja/api",    "version": "v1.0"    }
```

{% endtab %}
{% endtabs %}

## Get Account Information

<mark style="color:blue;">`GET`</mark> `https://api.brink.trade/account/:owner`

This will return the account information associated with the owner address provided.

#### Path Parameters

| Name           | Type   | Description                            |
| -------------- | ------ | -------------------------------------- |
| owner\_address | string | Ethereum address, owner of the account |

{% tabs %}
{% tab title="200 The Brink account address associated with the owner address is returned." %}

```
{    "account": "0x3F62d3Ca386175E65154732910DB76aEcB4024e1"    }ThaccountFromOwner() Error: 'Insert into messages' is not a valid address
```

{% endtab %}

{% tab title="400 The given owner address was not and Ethereum address." %}

```
{
    "err": "accountFromOwner() Error: not_an_address is not a valid address",
    "code": 400
}
```

{% endtab %}
{% endtabs %}

## Get Account Tokens

<mark style="color:blue;">`GET`</mark> `https://api.brink.trade/account_tokens/:owner`

Given an owner address, this API will return the token addresses of the owned tokens of the Brink account associated with that owner address , as well as the Brink account address

#### Path Parameters

| Name  | Type   | Description                            |
| ----- | ------ | -------------------------------------- |
| owner | string | Ethereum address, owner of the account |

{% tabs %}
{% tab title="200 The Brink account address and the tokens associated with it." %}

```
{    "account": "0x3F62d3Ca386175E65154732910DB76aEcB4024e1",    "tokens": ["0x6b175474e89094c44da98b954eedeac495271d0f", "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984"]    }
```

{% endtab %}

{% tab title="400 The given owner address was not an Ethereum address." %}

```
{
    "err": "accountFromOwner() Error: not_an_address is not a valid address",
    "code": 400
}
```

{% endtab %}
{% endtabs %}

## Get Account Messages

<mark style="color:blue;">`GET`</mark> `https://api.brink.trade/account_messages/:owner`

Get messages associated with the owner address's account

#### Path Parameters

| Name  | Type   | Description                            |
| ----- | ------ | -------------------------------------- |
| owner | string | Ethereum address, owner of the account |

{% tabs %}
{% tab title="200 The Brink account address and the associated signed messages." %}

```
{    "account": "0x3F62d3Ca386175E65154732910DB76aEcB4024e1",    "messages": ["0x6b175474e89094c44da98b954eedeac495271d0f", "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984"]    }
```

{% endtab %}

{% tab title="400 The given owner address was not an Ethereum address." %}

```
{
    "err": "accountFromOwner() Error: not_an_address is not a valid address",
    "code": 400
}
```

{% endtab %}
{% endtabs %}

## Get Messages

<mark style="color:blue;">`GET`</mark> `https://api.brink.trade/messages?states=UNDER_LIMIT,UNDER_PROFIT`

Get all messages with the selected states. State is Brink's own internal determination of the message's current state. \
\
You can pass in the following options individually:\
**ALL** will return every message\
**EXECUTABLE** will return all executable messages \
(Executable: QUEUED, IN\_PROGRESS, INSUFFICIENT\_FUNDS, RETRY, UNDER\_LIMIT, UNDER\_PROFIT)\
*(Note this does not mean they are profitable)*\
\
The full list of possible states are as follows:\
**QUEUED**: A message that is in our SQS queue and will soon be handled\
**IN\_PROGRESS**: A message that is currently being evaluated by one of our executors\
**INSUFFICIENT\_FUNDS:** A message that occurs when an account does not have the required funds for the transaction to be successful, but would otherwise be executable\
**RETRY:**  A message that has either failed between 1-5 transactions, was not executed because of executor error, or is in this state by default once created. Once a transaction fails more than 5 messages, the state becomes 'NEVER\_EXECUTABLE'\
**UNDER\_LIMIT:** A message that when last evaluated could not be executed because the requested limit had not yet been crossed\
**UNDER\_PROFIT:** A message the when last evaluated had crossed the limit threshold, but the profit for the executor would not cover gas costs\
**NEVER\_EXECUTABLE:** A message that has been determine to be never executable by our executors\
*Note if no state parameter is provided, the API will default to **ALL***

#### Query Parameters

| Name   | Type   | Description                                   |
| ------ | ------ | --------------------------------------------- |
| states | string | Comma separated states or an individual state |

{% tabs %}
{% tab title="200 All messages of the requested state." %}

```
{"messages":
    [
        {
            "message":"0xe70ac0a98a8a9c84c855d8e6a529507c66b19eb02f97b058ea24218f20eb711f",
            "signature":"0x7ee483de0dd7b0db1a59efff36b5e21be0022fe4e7a4b9f1ff057610fb181dd2280544a268acf0a812c698e46e875ec5c5da730d05b5a66b2b5f86144884f0ac1c",
            "signer":"0xb4dc65f8ade347d9d87d0d077f256afc798c4dc6",
            "accountAddress":"0x8aa5eef4d4b2b5d7354cc1d923ad6d3fe9e664aa",
            "functionName":"metaDelegateCall",
            "signedParams":
                [
                    {
                        "name":"to",
                        "type":"address",
                        "value":"0xa96dc3076db393e83139c807227e53b54b007073"
                    },
                    {
                        "name":"data",
                        "type":"bytes",
                        "value":"0xdc0ed0fe00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000cfd77caf9160909b361f597c94ff27e05ca6c8800000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000013ee0fc2914b9d1109ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
                        "callData":
                            {
                                "functionName":"ethToToken",
                                "params":
                                    [
                                        {
                                            "name":"bitmapIndex",
                                            "type":"uint256",
                                            "value":"0"
                                        },
                                        {
                                            "name":"bit",
                                            "type":"uint256",
                                            "value":"1"
                                        },
                                        {
                                            "name":"token",
                                            "type":"address",
                                            "value":"0xcfd77caf9160909b361f597c94ff27e05ca6c880"
                                        },
                                        {
                                            "name":"ethAmount",
                                            "type":"uint256",
                                            "value":"1000000000000000000"
                                        },
                                        {
                                            "name":"tokenAmount",
                                            "type":"uint256",
                                            "value":"367642280835453620489"
                                        },
                                        {
                                            "name":"expiryBlock",
                                            "type":"uint256",
                                            "value":"115792089237316195423570985008687907853269984665640564039457584007913129639935"
                                        },
                                        {
                                            "name":"to",
                                            "type":"address"
                                        },
                                        {
                                            "name":"data",
                                            "type":"bytes"
                                        }
                                    ]
                                }
                            }
                        ],"failedTxs":[],"pendingTxs":[]
                    }
                ]
}
```

{% endtab %}

{% tab title="400 If the input does not exist or is not a state listed above." %}

```
{
    "err": "UNDER_WATER is not a valid QUEUE_STATE",
    "code": 400
}
```

{% endtab %}
{% endtabs %}

## Get Events

<mark style="color:blue;">`GET`</mark> `https://api.brink.trade/events`

The Get Events API is a server-sent event stream that allows you to retrieve new messages as they are inserted into the database.\
\
In the code block below you will find a reference implementation on the client side (Node.js)\
`const EventSource = require("eventsource")`\
``const source = new EventSource(`https://api.brink.trade`)``\
`source.addEventListener('message', message => { console.log(message) })`

{% tabs %}
{% tab title="200 Messages such as the one below will be pushed to your client when they are inserted into the database." %}

```
MessageEvent {
  type: 'message',
  data: 
      {
        "message": "0x4b4c4eeb5474afc041f3f966f125035fac103c59327d83093bdc6369721eb596",
        "signature": "0x210988d0b3842f3163604372c2b487500520cca44c89823234a0563ae549012841fea5b2f56f3ca1e33a5148b9d4078c5499a1399a6f158e0f868029f1a7c8ff1c",
        "signer": "0xea5dfd42f8d668d910478efab56c4f5c45375879",
        "accountAddress": "0xf43f82e8a0a30603681c855245264bdc11c6c655",
        "functionName": "metaDelegateCall",
        "signedParams": [
            {
                "name": "to",
                "type": "address",
                "value": "0xa96dc3076db393e83139c807227e53b54b007073"
            },
            {
                "name": "data",
                "type": "bytes",
                "value": "0xdc0ed0fe00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000e7b9d7cd757a1a6838985c83c7f571346ee78e810000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000016d5ed6dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
                "callData": {
                    "functionName": "ethToToken",
                    "params": [
                        {
                            "name": "bitmapIndex",
                            "type": "uint256",
                            "value": "0"
                        },
                        {
                            "name": "bit",
                            "type": "uint256",
                            "value": "1"
                        },
                        {
                            "name": "token",
                            "type": "address",
                            "value": "0xe7b9d7cd757a1a6838985c83c7f571346ee78e81"
                        },
                        {
                            "name": "ethAmount",
                            "type": "uint256",
                            "value": "1000000000000000000"
                        },
                        {
                            "name": "tokenAmount",
                            "type": "uint256",
                            "value": "383118701"
                        },
                        {
                            "name": "expiryBlock",
                            "type": "uint256",
                            "value": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
                        },
                        {
                            "name": "to",
                            "type": "address"
                        },
                        {
                            "name": "data",
                            "type": "bytes"
                        }
                    ]
                }
            }
        ],
        "failedTxs": [],
        "pendingTxs": []
    },
  origin: 'http://localhost:3001'
}
```

{% endtab %}
{% endtabs %}

## Submit Message

<mark style="color:green;">`POST`</mark> `https://api.brink.trade/submit_message`

Submit a signed message to the database to be executed

#### Request Body

| Name          | Type   | Description                                        |
| ------------- | ------ | -------------------------------------------------- |
| signedMessage | object | Signed messages can be created using the Brink SDK |

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

```
```

{% endtab %}
{% endtabs %}
