# Relay

## Execute Relay Transaction

<mark style="color:green;">`POST`</mark> `https://gateway-relay.herokuapp.com/api/relay/execute`

#### Headers

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

#### Request Body

| Name                                                    | Type   | Description                                                                                                                      |
| ------------------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------- |
| keyManagerAddress<mark style="color:red;">\*</mark>     | string | address of the keymanager that controls the UP of the user sending this relay transaction                                        |
| transaction.abi<mark style="color:red;">\*</mark>       | string | the encoded ABI of the transaction being sent                                                                                    |
| transaction.signature<mark style="color:red;">\*</mark> | string | the transaction signature, signed by someone who has CALL and TRANSFER permissions to the UP involved in sending the transaction |
| transaction.nonce<mark style="color:red;">\*</mark>     | number | the nonce of the keymanager contract                                                                                             |

{% tabs %}
{% tab title="201: Created successful operation" %}
{% code title="Example 201 Response" overflow="wrap" %}

```javascript
{
    transactionHash: '0x8fe07e8d16e284386de85b5d42883c1f7c6dfbee2047c69b4a60117466087053'
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request malformed request error" %}
{% code title="Example 400 Response" overflow="wrap" %}

```javascript
{
    error: 'Malformed request, please ensure the following parameters are included: keyManagerAddress, transaction'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to execute. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Get User Credit Quota&#x20;

<mark style="color:green;">`POST`</mark> `https://gateway-relay.herokuapp.com/api/relay/quota`

#### Headers

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

#### Request Body

| Name                                        | Type    | Description                                                                |
| ------------------------------------------- | ------- | -------------------------------------------------------------------------- |
| address<mark style="color:red;">\*</mark>   | string  | UP address associated with the user in question                            |
| timestamp<mark style="color:red;">\*</mark> | integer | timestamp of when the request is being sent +/- 5 seconds                  |
| signature<mark style="color:red;">\*</mark> | string  | a message signed by a controller key with SIGN permission on the user's UP |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" overflow="wrap" %}

```javascript
{
    quota: 100, //describes current credit amount
    unit: 'credits',
    totalQuota: 100, //will be 0 if user is not subscribed
    resetDate: 1664380478 //will be -1 if user is not subscribed
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request malformed request error" %}
{% code title="Example 400 Response" overflow="wrap" %}

```javascript
{
    error: 'Malformed request, please ensure the following parameters are included: quota, unit, totalQuota, resetDate'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found user not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'No user found with provided address: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to quota. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Get Transaction Status

<mark style="color:green;">`POST`</mark> `https://gateway-relay.herokuapp.com/api/relay/transactionStatus`

#### Headers

| Name                                            | Type      | Description                                                                                                                                                                                                                                                                         |
| ----------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | jwt token | received via authenticating with the [auth endpoints.](https://karan-khullar.gitbook.io/gateway/documentation/api-reference/auth) **To learn more about the authentication flow, click** [**here**](https://karan-khullar.gitbook.io/gateway/architecture/authentication-flow)**.** |

#### Request Body

| Name                                              | Type   | Description                                                                         |
| ------------------------------------------------- | ------ | ----------------------------------------------------------------------------------- |
| transactionHash<mark style="color:red;">\*</mark> | string | the transaction hash associated with the transaction whose status is being received |

{% tabs %}
{% tab title="200: OK successful operation" %}
{% code title="Example 200 Response" %}

```javascript
{
    status: 'Success',
    transactionSenderAddress: 0x218C2BbaaBa0D66ddcD5De942Ed2980Bbfd1f004,
    creditsUsed: 2.1,
    creditsBefore: 7.1,
    creditsAfter: 5
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request malformed request error" %}
{% code title="Example 400 Response" overflow="wrap" %}

```javascript
{
    error: 'Malformed request, please ensure the following parameters are included: transactionHash'
}
```

{% endcode %}
{% endtab %}

{% tab title="404: Not Found transaction not found error" %}
{% code title="Example 404 Response" overflow="wrap" %}

```javascript
{
    error: 'Transaction was not sent through the Gateway Relay Service. Transaction hash: 0xcd56ff1157e172bfed0310526ac14c135d59628eb046a62ac71ed7380585cf87'
}
```

{% endcode %}
{% endtab %}

{% tab title="500: Internal Server Error internal server error" %}
{% code title="Example 500 Response" overflow="wrap" %}

```javascript
{
    error: 'An internal server error occurred. Please check the request body, ensure you are authenticated, and try again.'
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized authentication error" %}
{% code title="Example 401 Response" overflow="wrap" %}

```javascript
{
    error: 'Unauthenticated call to transactionStatus. Please re-authenticate and try again.'
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
