# Withdrawal

TanX offers various [SDKs](https://docs.tanx.fi/tech/api-documentation/sdk-reference) in different languages to facilitate seamless withdrawal. This document outlines the withdrawal process through the JavaScript (JS) SDK. For additional SDK options, refer to the [SDK Reference](https://docs.tanx.fi/tech/api-documentation/sdk-reference)

{% hint style="info" %}
Please visit [tanX website](https://tanx.fi) and create an account using your wallet before proceeding with the below steps.
{% endhint %}

## Withdrawal Process

### 1. Install the NPM Package

```bash
npm i @tanx-libs/tanx-connector
```

### 2. Create an Instance

```javascript
import { Client } from '@tanx-libs/tanx-connector';

// Create an instance with either testnet or mainnet
const client = new Client();
// or
const client = new Client('testnet'); // default is mainnet
```

### Withdrawal **Options**

Generally, we have two modes of withdrawal: **Normal Withdrawal** and **Fast Withdrawal**. For withdrawal methods that require a signer and provider, please refer to the deposit method mentioned above.

### **1. Normal** Withdrawal

With Normal Withdrawal, your requested funds will be processed within a standard time frame (<mark style="color:purple;">24 hours</mark>). This mode is suitable for users who are not in a rush to access their funds and are comfortable with the regular processing time.

#### **Normal Withdrawal Process:**

1. **Initiate Your Withdrawal Request:** Call the `initiateNormalWithdrawal` function with the following parameters:<br>

   ```javascript
   const withdrawalRes = await client.initiateNormalWithdrawal(
     keyPair, // The keyPair created above
     0.0001, // Enter the amount you want to withdraw
     'usdc', // Enter the coin symbol
   )
   ```

2. **Wait for Confirmation:** Wait for up to 24 hours.<br>

3. **Check Pending Withdrawal Balance:** Use the `getPendingNormalWithdrawalAmountByCoin` function with the required parameters to check if the withdrawn balance is pending:

   ```javascript
    const pendingBalance = await client.getPendingNormalWithdrawalAmountByCoin(
     'eth', // Enter the coin symbol
     ethAddress, // User public ETH address
     signer, // The signer created above
   )
   ```

4. **Complete Withdrawal:** If the pending balance is greater than 0, use the `completeNormalWithdrawal` function to withdraw the cumulative amount to your ETH wallet:<br>

   ```javascript
   const completeNWRes = await client.completeNormalWithdrawal(
     'eth', // Enter the coin symbol
     ethAddress, // User public ETH address
     signer, // The signer created above
   )
   ```

#### **Get a List of Normal Withdrawals:**

Retrieve a list of normal withdrawals with optional pagination:

```javascript
const withdrawalsList = await client.listNormalWithdrawals({
  page: 2, // This field is optional
})
```

### 2. **Fast Withdrawal**

With Fast Withdrawal, your funds will be processed in an expedited timeframe, often within a few minutes. This mode is ideal for users who require immediate access to their funds and are comfortable with paying a fee.

```javascript
const fastWithdrawalRes = await client.fastWithdrawal(
  keyPair, // The keyPair created above
  0.0001, // Enter the amount you want to deposit
  'usdc', // Enter the coin symbol
  'ETHEREUM', // Allowed networks include 'ETHEREUM', 'POLYGON', 'OPTIMISM', 'ARBITRUM', 'LINEA', 'SCROLL', 'STARKNET' and 'MODE'
)
```

#### **Get a List of Fast Withdrawals:**

Retrieve a list of fast withdrawals with optional pagination:

```javascript
const withdrawalsList = await client.listFastWithdrawals({
  page: 2, // This field is optional
  network: 'ETHEREUM', // Allowed networks include 'ETHEREUM', 'POLYGON', 'OPTIMISM', 'ARBITRUM', 'LINEA', 'SCROLL', 'STARKNET' and 'MODE'
})
```

\
For additional information, please refer to the [SDK Reference](https://docs.tanx.fi/tech/api-documentation/sdk-reference).
