# REST API

To interact with the REST API, it is required to set the header `Content-Type: application/json` and send a JSON payload containing values for the fields specified below, or if no inputs are described, an empty object can be supplied.

## /address

Retrieves the `pint1` address associated with the daemon's connection to pintp2p.

```bash
pintswap-cli address
```

## /ethereum-address

Retrieves the Ethereum wallet address associated with the daemon which is used to sign spends involved in trades.

```bash
pintswap-cli ethereum-address
```

## &#x20;/peer

Retrieves the orderbook hosted by a remote peer on the PintSwap network, as well as any other details hosted by the peer, including the bio

Inputs:

```bash
{
  "peer": "QmQ8e4HF8Vxw4Ep7mdQjvphZJwDhjLUAoXqmEzftZnyAK2"
}
```

A .drip name can be used in place of a pint address, if one is registered

```bash
{
  "peer": "wock.drip"
}
```

<pre class="language-bash"><code class="lang-bash">pintswap-cli peer --peer wock.drip

#{
#  "offers": [
<strong>#    {
</strong>#      "gets": {
#        "amount": "0x0e22fac675c8c8",
#        "token": "0x0000000000000000000000000000000000000000"
#      },
#      "gives": {
#        "amount": "0x6eca1d",
#        "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
#      },
#      "id": "0xb0bbfbf1d64037a456f3e1f01f1149017bec1618d506dfa6a42d217205269cc9"
#    },

# List will continue for all offers

# "bio": "fwm I always got it"
</code></pre>

## &#x20;/peer-image

Pipes binary data to stdout containing the PNG image content for a PeerId profile picture. Should be redirected to a file. Inputs can be a pint address or a .drip name.

Inputs:

```bash
{
  "peer": "wock.drip"
}
```

```bash
pintswap-cli peer-image --peer wock.drip > ~/wock.png
```

## &#x20;/add

Adds a limit order to the local orderbook. If the order exists on the daemon, it can be taken by anyone who dials the peer with the /trade function, whether or not the node is actively publishing. It only requires the pint address of the daemon to trade against it, or otherwise the .drip name registered, if there is one.

Inputs:

```bash
{
  "getsToken": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  "getsAmount": "0x102f40a4",
  "givesToken": "0x8d008CAC1a5CB08aC962b1e34E977B79ABEee88D",
  "givesAmount": "0x14c7ec8e56a7fc000000"
}
```

```bash
pintswap-cli add --gets-token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 --gets-amount 0x102f40a4 --gives-token 0x8d008CAC1a5CB08aC962b1e34E977B79ABEee88D --gives-amount 0x14c7ec8e56a7fc000000

#0xcfb8673b6c96f217aa47ea68cc1c5a3ff77c728f1b775f59e3e9ed23b49d34cf
```

## &#x20;/limit

Alternative syntax for the functionality in /add, which will adjust for a decimals() value automatically, so a floating point value can be used with the RPC for a price and amount.

Inputs:

```bash
{
  "price": "0.00267",
  "amount": "100",
  "type": "sell",
  "pair": "0x8d008CAC1a5CB08aC962b1e34E977B79ABEee88D/USDC"
}
```

```bash
pintswap-cli limit --price 0.00267 --amount 100 --type sell --pair 0x8d008CAC1a5CB08aC962b1e34E977B79ABEee88D/USDC
```

## &#x20;/offers

Retrives the local orders hosted on the daemon process which will be published if /publish is invoked.

<pre class="language-bash"><code class="lang-bash">pintswap-cli offers
<strong>
</strong>#[
#  {
#    "gives": {
#     "token": "0x8d008CAC1a5CB08aC962b1e34E977B79ABEee88D",
#      "amount": "0x14c7ec8e56a7fc000000"
#    },
#    "gets": {
#      "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
#      "amount": "0x102f40a4"
#    },
#    "id": "0xcfb8673b6c96f217aa47ea68cc1c5a3ff77c728f1b775f59e3e9ed23b49d34cf"
#  }
#]

</code></pre>

## &#x20;/delete

Deletes an order from the local orderbook hosted on the daemon process.

```bash
{
   "id": "<orderhash>"
}
```

```bash
pintswap-cli delete --id 0xcd9305ed3975e3c0ad35f9169e75d386c63a21f4fa21433b2a97332336b39ad4

#true if deleted
#false if not
```

## &#x20;/clear

Deletes the entire local orderbook hosted on the daemon process.

```bash
pintswap-cli clear
#0
```

## &#x20;/publish

Begins publishing the orderbook local to the daemon. This must be called after the daemon initializes or your orders will not be visible on the public orderbook.

Example:

```bash
pintswap-cli publish
#OK
```

## &#x20;/subscribe

Begins listening fo orderbook publishes on the PintSwap network. Orders will accumulate and can thereafter be queried with the /orderbook route. If this API endpoint is not called after the daemon initializes the /orderbook route will respond with an empty list.

```bash
pintswap-cli subscribe
#OK
```

## &#x20;/unsubscribe

Stops listening for orderbook publishes on the PintSwap network.

```bash
pintswap-cli unsubscribe
#OK
```

## &#x20;/orderbook

Returns a view of the complete orderbook and associated PeerId for each offering.

```bash
pintswap-cli orderbook

#[
#  "pint1zgsp4ga24uswa954kf03w3jhw5ad5qq5kgt90ykn560aktkussv9h2gyc5cjp",
#  [
#    {
#      "gets": {
#        "amount": "0x0429d069189e0000",
#        "token": "0x0000000000000000000000000000000000000000"
#      },
#      "gives": {
#        "tokenId": "0x01",
#        "token": "0x0B2403086af285de8E1B897E7404E3d5CBb1Bb10"
#      },
#      "id": "0xd26e819196d5a0aff1ab71f86ec349fdae5d7ba2f563d4672292ee3d79ca6650"
#    },
# All orders and PeerId's will be listed
```

## &#x20;/trade

Attempts to negotiate a trade aggregating the complete set of orderid/amount pairs supplied, with the targeted peer. Supports the `broadcast: true` property which, if set, will attempt to execute the trade transactions as a bundle using the flashbots relay API.

A /trade invocation can only execute if the base asset / trade asset pair are consistent throughout the list of orders to take, and they all must be offered by the same peer. This is true for any trade execution on the PintSwap protocol, whether it is by the daemon or the webapp that is being called to perform the trade.

Inputs:

```bash
{
  "peer": "wock.drip",
  "trades": [{
    "offerHash": "0x44bdebb961a61ed9413fc1d950dad4cf9bf6410e4a95dbff7c2459bcc065ef6b",
    "amount": "0x20f5612972944a000000"
  }, {
    "offerHash": "0xcd9305ed3975e3c0ad35f9169e75d386c63a21f4fa21433b2a97332336b39ad4",
    "amount": "0x14c7ec8e56a7fc000000"
  }],
  "broadcast": true
}
```

```bash
pintswap-cli trade --peer wock.drip --trades 0x44bdebb961a61ed9413fc1d950dad4cf9bf6410e4a95dbff7c2459bcc065ef6b,0x20f5612972944a000000,0xcd9305ed3975e3c0ad35f9169e75d386c63a21f4fa21433b2a97332336b39ad4,0x14c7ec8e56a7fc000000 --broadcast
```

## &#x20;/register

Registers a name on the .drip nameserver peers. Can only be unregistered with the PeerId used to register. Further work is planned to improve name resolution access control and mutability. For now, ensure you do not lose your PeerId if you intend to keep your .drip name.

Inputs:

```bash
{
  "name": "wock.drip"
}
```

```bash
pintswap-cli register --name wock.drip
#0
```

## &#x20;/resolve

Resolves a `.drip` name to a pint address. Can also be used to do reverse lookups

Inputs:

```bash
{
  "name": "wock.drip"
}
```

<pre class="language-bash"><code class="lang-bash">pintswap-cli resolve --name wock.drip
<strong>#pint1zgsw52stcg9kgy4y6qvl3rpu0dzwzdcy9m3yy4mdnfm22c5ht90jh8qtvlwzh
</strong></code></pre>

## &#x20;/set-bio

Sets the bio associated with your daemon process, as visible on the webapp.

Inputs:

```bash
{
  "bio": "fwm I always got it"
}
```

```bash
pintswap-cli set-bio --bio 'fwm I always got it'
#OK
```

## &#x20;/set-image

Sets the profile picture associated with your daemon process, as visible on the webapp.

Inputs:

```typescript
{
  "image": "<base64 encoded PNG>"
}
```

```bash
pintswap-cli set-image --image ./wock.png
```

## ws\://localhost:42161

Open a WebSocket connection to ws\://: as specified by the environment to begin receiving logs in the form

```bash
{
  "type": "log",
  "message": {
    "logLevel": "info"
    "timestamp": 1691183404902,
    "data": "initiating trade",
  }
}
```

```bash
pintswap-cli attach
```


---

# 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://pintswap.gitbook.io/pintswap/pintswap-daemon/rest-api.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.
