# Check Approve Transaction Status

## Check Approval API

In  `EVM`,  `TRON` and `STARKNET` blockchains where [swap](https://docs.rango.exchange/api-integration/basic-api-single-step/create-transaction-swap#swap-response) returns a non-null value for approve transaction (e.g. `approveData` and `approveTo` fields in case of the `EVM`), you need to use these values to prepare the approve transaction for the user and call `isApproved` periodically to see if the approval transaction is completed. After a successful check, you should ask the user to sign the main transaction.

{% hint style="warning" %}
**Caution:**

It is important to use approve transaction data generated by Rango API and not hard-coding something on your client side for creating approve transaction, because for some protocols (some bridges), the contract that should be approved is dynamically generated via their API based on the route.&#x20;
{% endhint %}

{% hint style="info" %}
For checking approval transaction status, you could check it directly from the RPC endpoint if you prefer and skip calling Rango API for this purpose.
{% endhint %}

{% tabs %}
{% tab title="Typescript‌ (SDK)" %}

```typescript
const transaction = await rango.isApproved(
    requestId = 'e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b',
    txId = '0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f'
)
```

{% endtab %}

{% tab title="Node.js (Axios)" %}

```javascript
const response = await axios.get('https://api.rango.exchange/basic/is-approved', {
  params: {
    'requestId': 'e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b',
    'txId': '0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f',
    'apiKey': 'c6381a79-2817-4602-83bf-6a641a409e32'
  }
});
```

{% endtab %}

{% tab title="Bash (cURL)" %}
{% code overflow="wrap" %}

```bash
curl --request GET \
     --url 'https://api.rango.exchange/basic/is-approved?requestId=e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b&txId=0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f&apiKey=c6381a79-2817-4602-83bf-6a641a409e32' 
```

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

{% embed url="<https://rango-api.readme.io/reference/isapproved>" %}
Check Approval Transaction Status Swagger
{% endembed %}

You could stop checking is-approved method if:

1. Approval transaction succeeded. => `isApproved === true`
2. Approval transaction failed. => `!isApproved && txStatus === 'failed'`
3. Approval transaction succeeded but `currentApprovedAmount` is still less than `requiredApprovedAmount` (e.g. user changed transaction data in wallet and enter another approve amount in MetaMask instead of default approve amount proposed by Rango API) => `!isApproved && txStatus === 'success'`

### Check Approval Request&#x20;

{% tabs %}
{% tab title="API Definition" %}

* **`requestId`** <mark style="color:red;">\*</mark> String
  * Description: The unique ID which is generated in the best route endpoint.
  * Example: `e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b`
* **`txId`** <mark style="color:red;">\*</mark> String
  * Description: Transaction hash that wallet returned for approve transaction.
  * Example: `0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f`
    {% endtab %}

{% tab title="SDK Models (Typescript)" %}

```typescript
function isApproved(requestId: string, txId?: string)
```

{% endtab %}
{% endtabs %}

### Check Approval Response&#x20;

{% tabs %}
{% tab title="API Definition" %}

* **`isApproved`**
  * Description: A flag which indicates that the approve tx is done or not.
* **`txStatus`**
  * Description: Status of approve transaction in blockchain (possible values are `success`, `running` and `failed`) If `isArppoved` is false and `txStatus` is failed, it means that approve transaction is failed in the blockchain.
* **`requiredApprovedAmount`**
  * Description: Required amount to be approved by user
* **`currentApprovedAmount`**
  * Description: Current approved amount by user
    {% endtab %}

{% tab title="SDK Models (Typescript)" %}

```typescript
export type CheckApprovalResponse = {
  isApproved: boolean
  txStatus: TransactionStatus | null
  requiredApprovedAmount: string | null
  currentApprovedAmount: string | null
}

export enum TransactionStatus {
  FAILED = 'failed',
  RUNNING = 'running',
  SUCCESS = 'success',
}
```

{% endtab %}

{% tab title="Sample Response" %}

```json
{
    "isApproved": true,
    "txStatus": "success",
    "currentApprovedAmount": "0.903658",
    "requiredApprovedAmount": "0.903658"
}
```

{% endtab %}
{% endtabs %}
