# Transactions

<table><thead><tr><th width="210">Attribute</th><th>Description</th></tr></thead><tbody><tr><td><code>amount</code></td><td>The amount to transfer from the <code>sender</code> account.</td></tr><tr><td><code>reference</code></td><td>A reference for the transaction.</td></tr></tbody></table>

<table><thead><tr><th width="210">Relationship</th><th>Description</th></tr></thead><tbody><tr><td><code>sender</code></td><td>The account to send this transaction <strong>from</strong>.</td></tr><tr><td><code>recipient</code></td><td>The account to send this transaction <strong>to</strong>.</td></tr></tbody></table>

<table><thead><tr><th width="210">Meta</th><th>Description</th></tr></thead><tbody><tr><td><code>exchangeRate</code></td><td>The exchange rate of the transaction, if applicable.</td></tr><tr><td><code>createdAt</code></td><td>The timestamp (UTC) (<a href="https://en.wikipedia.org/wiki/ISO_8601">ISO8601</a>) when the transaction was created.</td></tr></tbody></table>

* `meta.exchangeRate` will be **omitted** if the two accounts are the same currency.

***

{% openapi src="<https://2742279370-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJTlJGD24d8T6euWbm1om%2Fuploads%2F7QefoZ1pPhsDSoic0seH%2Fswagger.yml?alt=media&token=f7398d06-a703-4b52-825a-3ea33efbed7c>" path="/transactions" method="get" expanded="true" %}
[swagger.yml](https://2742279370-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJTlJGD24d8T6euWbm1om%2Fuploads%2F7QefoZ1pPhsDSoic0seH%2Fswagger.yml?alt=media\&token=f7398d06-a703-4b52-825a-3ea33efbed7c)
{% endopenapi %}

***

{% openapi src="<https://2742279370-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJTlJGD24d8T6euWbm1om%2Fuploads%2F7QefoZ1pPhsDSoic0seH%2Fswagger.yml?alt=media&token=f7398d06-a703-4b52-825a-3ea33efbed7c>" path="/transactions" method="post" expanded="true" %}
[swagger.yml](https://2742279370-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJTlJGD24d8T6euWbm1om%2Fuploads%2F7QefoZ1pPhsDSoic0seH%2Fswagger.yml?alt=media\&token=f7398d06-a703-4b52-825a-3ea33efbed7c)
{% endopenapi %}

* You cannot edit or delete a transaction after created.

***

{% openapi src="<https://2742279370-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJTlJGD24d8T6euWbm1om%2Fuploads%2F7QefoZ1pPhsDSoic0seH%2Fswagger.yml?alt=media&token=f7398d06-a703-4b52-825a-3ea33efbed7c>" path="/transactions/{transactionId}" method="get" expanded="true" %}
[swagger.yml](https://2742279370-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJTlJGD24d8T6euWbm1om%2Fuploads%2F7QefoZ1pPhsDSoic0seH%2Fswagger.yml?alt=media\&token=f7398d06-a703-4b52-825a-3ea33efbed7c)
{% endopenapi %}

***

## Examples

### Crediting your account

* You can credit your account by specifying ["`ROOT`"](https://www.testbank.dev/accounts#the-root-account) as the `sender` account ID, and one of your accounts as the `recipient`.
* This is a **Create** event, similar to minting new coin, where you receive "funds" from nothing.
* Yes, you can credit your account insane amounts (but it's not real!).

```http
POST /transactions HTTP/1.1
Content-Type: application/json
{
  "data": {
    "type": "transactions",
    "attributes": {
      "amount": "100.00",
      "reference": "Opening account"
    },
    "relationships": {
      // Specify ROOT as the sender
      "sender": { "data": { "type": "accounts", "id": "ROOT" } },
      // Specify one of your accounts as the recipient
      "recipient": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } }
    },
    "meta": {
      "externalId": "b20e7841-39f4-4581-b858-c023c51ab463"
    }
  }
}

HTTP/1.1 201 Created
Content-Type: application/json
{
  "data": {
    "type": "transactions",
    "id": "01H5B3X62ENSWZBV0ZNXW7H9A4",
    "attributes": {
      "amount": "100.00",
      "reference": "Opening account"
    },
    "relationships": {
      "sender": { "data": { "type": "accounts", "id": "ROOT" } },
      "recipient": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } }
    },
    "meta": {
      "externalId": "b20e7841-39f4-4581-b858-c023c51ab463"
    }
  }
}
```

### Emptying your account

* You can empty your account by specifying ["`ROOT`"](https://www.testbank.dev/accounts#the-root-account) as the `recipient` account ID.
* This is a **Destroy** event, where you send "funds" into nothing.

```http
POST /transactions HTTP/1.1
Content-Type: application/json
{
  "data": {
    "type": "transactions",
    "attributes": {
      "amount": "100.00",
      "reference": "Closing account"
    },
    "relationships": {
      // Specify one of your accounts as the sender
      "sender": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } },
      // Specify ROOT as the recipient
      "recipient": { "data": { "type": "accounts", "id": "ROOT" } }
    },
    "meta": {
      "externalId": "b20e7841-39f4-4581-b858-c023c51ab463"
    }
  }
}

HTTP/1.1 201 Created
Content-Type: application/json
{
  "data": {
    "type": "transactions",
    "id": "01H5B3X62ENSWZBV0ZNXW7H9A4",
    "attributes": {
      "amount": "100.00",
      "reference": "Closing account"
    },
    "relationships": {
      "sender": { "data": { "type": "accounts", "id": "ROOT" } },
      "recipient": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } }
    },
    "meta": {
      "externalId": "b20e7841-39f4-4581-b858-c023c51ab463"
    }
  }
}
```

### Transfer between 2 accounts

You can transfer funds between 2 accounts by specifying the relevant `recipient` account ID.

```http
POST /transactions HTTP/1.1
Content-Type: application/json
{
  "data": {
    "type": "transactions",
    "attributes": {
      "amount": "100.00",
      "reference": "Lunch money"
    },
    "relationships": {
      // Specify one of your accounts as the sender
      "sender": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } },
      // Specify another of your accounts as the sender
      "recipient": { "data": { "type": "accounts", "id": "f6g7h8i9j0" } }
    },
    "meta": {
      "externalId": "b20e7841-39f4-4581-b858-c023c51ab463"
    }
  }
}

HTTP/1.1 201 Created
Content-Type: application/json
{
  "data": {
    "type": "transactions",
    "id": "01H5B3X62ENSWZBV0ZNXW7H9A4",
    "attributes": {
      "amount": "100.00",
      "reference": "Lunch money"
    },
    "relationships": {
      "sender": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } },
      "recipient": { "data": { "type": "accounts", "id": "a1b2c3d4e5" } }
    },
    "meta": {
      "externalId": "b20e7841-39f4-4581-b858-c023c51ab463"
    }
  }
}
```

* You can transfer from any of your accounts.
* You can transfer to any of your accounts, or any public/unlisted account.

{% hint style="danger" %}
As of now, you cannot transfer between accounts of different currencies.

Currency conversion will be addressed in a future version of this API.
{% endhint %}
