> For the complete documentation index, see [llms.txt](https://xpansionchain-1.gitbook.io/xpansionchain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xpansionchain-1.gitbook.io/xpansionchain/guides/basic-guides/crypto-on-and-off-ramps.md).

# Crypto on and off-ramps

## Crypto on and off-ramps

Typically, getting crypto onto XpansionChain Layer 2 wallets is a multi-step process. A common flow is:

1. A user obtains crypto on L1 (such as by purchasing it on an exchange like Coinbase)
2. Transfers it from the exchange to an L1 wallet that they own
3. Deposits it from the L1 wallet to their XpansionChain L2 wallet

However, there are crypto on-ramp and off-ramp providers that enable users to get crypto in and out of L2 wallets in a ***single step***. XpansionChain makes it easy for you to integrate with the following providers via our SDKs and API:

| Provider                                   | How does it work?                                                                                               | Fees                                                           | Min. purchase / deposit   | Restrictions                                                                                                                                                                                                                                                                                                                                                                                                          |
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <mark style="color:blue;">MoonPay</mark>   | Users can buy crypto with a card payment and it is immediately transferred to their L2 wallet                   | See <mark style="color:blue;">MoonPay's transaction fee</mark> | $20USD                    | <p>See these lists of <em><strong>non-supported</strong></em> countries:<br>- <a href="https://support.moonpay.com/hc/en-gb/articles/6557330712721-What-are-our-non-supported-countries-states-and-territories-for-on-ramp-product-">On-ramp</a><br>- <a href="https://support.moonpay.com/hc/en-gb/articles/360009279877-What-are-our-non-supported-countries-states-and-territories-for-off-ramp-">Off-ramp</a></p> |
| <mark style="color:blue;">Layerswap</mark> | Users can transfer crypto they own in a centralised exchange account (ie. Coinbase) directly to their L2 wallet | See <mark style="color:blue;">Layerswap's transfer fees</mark> | 0.009ETH / 15IMX / 12USDC |                                                                                                                                                                                                                                                                                                                                                                                                                       |

📝GUIDES

* <mark style="color:blue;">Core SDK</mark>
  * <mark style="color:blue;">On-ramp</mark>
  * <mark style="color:blue;">Off-ramp</mark>
* Link SDK:
  * <mark style="color:blue;">On-ramp</mark>
  * <mark style="color:blue;">Off-ramp</mark>
* <mark style="color:blue;">API</mark>

### Core SDK[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#core-sdk) <a href="#core-sdk" id="core-sdk"></a>

Currently, this functionality is only available in the Typescript Core SDK. Please refer to the API endpoints referenced in each step for other implementations. The full list of endpoints required are also listed <mark style="color:blue;">here</mark>.

### On-ramp[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#on-ramp) <a href="#on-ramp" id="on-ramp"></a>

#### 1. Initialize the Core SDK[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#1-initialize-the-core-sdk) <a href="#id-1-initialize-the-core-sdk" id="id-1-initialize-the-core-sdk"></a>

In order to use the Core SDK, you need to <mark style="color:blue;">initialize it</mark>.

#### 2. Create the on-ramp request[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#2-create-the-on-ramp-request) <a href="#id-2-create-the-on-ramp-request" id="id-2-create-the-on-ramp-request"></a>

📚API REFERENCE

* <mark style="color:blue;">createExchange</mark>

📚SDK REFERENCE

* <mark style="color:blue;">createExchange</mark>

* MoonPay

```
const exchangeTxnParams: ExchangesApiCreateExchangeRequest = {
  createExchangeAPIRequest: {
    provider: 'moonpay',
    type: 'onramp',
    wallet_address: '0xqw2...', // L2 wallet
    widget: { theme: 'light' },
  },
};

const exchangeTxnResponse = await imxClient.createExchange(exchangeTxnParams);
```

This displays the UI with the loaded MoonPay widget.

The user will be asked to provide credit card details: ![MoonPay widget](https://docs.x.immutable.com/assets/images/moonpay-widget-18139bf360cc908254e25891aeb9e4f4.png)

After creating a transaction successfully, you will be provided with the specified provider's widget URL to be rendered where users can proceed with transfer.

The user proceeds with transfer details on the provider's widget.

* Layerswap

```
const exchangeTxnParams: ExchangesApiCreateExchangeRequest = {
  createExchangeAPIRequest: {
    provider: 'layerswap',
    type: 'onramp',
    wallet_address: '0xqw2...', // L2 wallet
    widget: { theme: 'light' },
  },
};

const exchangeTxnResponse = await imxClient.createExchange(exchangeTxnParams);
```

This displays the UI with the loaded Layerswap widget.

The user will be asked to connect to the exchange they want to use: ![Layerswap widget](https://docs.x.immutable.com/assets/images/layerswap-widget-e79bafb51a180aa91b26d8de2bb2dfcc.png)

After creating a transaction successfully, you will be provided with the specified provider's widget URL to be rendered where users can proceed with transfer.

The user proceeds with transfer details on the provider's widget.

#### 3. Verify the transaction status[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#3-verify-the-transaction-status) <a href="#id-3-verify-the-transaction-status" id="id-3-verify-the-transaction-status"></a>

📚API REFERENCE

* <mark style="color:blue;">createExchange</mark>

📚SDK REFERENCE

* <mark style="color:blue;">getExchange</mark>

Please consider checking the transaction status in a polling fashion in the background.

```
const getExchangeTransactionResponse = await imxClient.getExchange({
  id: exchangeTxnResponse.id,
});
```

The transfer process can take few minutes and during that time transaction can return a `pending` or `waitingPayment` status while it's still being processed. The final stage of transaction status can be:

* `completed` - successful completion
* `failed` - failure encountered

Upon reaching final stage of the transaction status, you can show an appropriate message, send a notification or update any state with the successful/failed transaction.

### Off-ramp[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#off-ramp) <a href="#off-ramp" id="off-ramp"></a>

#### 1. Initialize the Core SDK[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#1-initialize-the-core-sdk-1) <a href="#id-1-initialize-the-core-sdk-1" id="id-1-initialize-the-core-sdk-1"></a>

In order to use the Core SDK, you need to <mark style="color:blue;">initialize it</mark>.

#### 2. Create the off-ramp request[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#2-create-the-off-ramp-request) <a href="#id-2-create-the-off-ramp-request" id="id-2-create-the-off-ramp-request"></a>

📚API REFERENCE

* <mark style="color:blue;">createExchange</mark>

📚SDK REFERENCE

* <mark style="color:blue;">createExchange</mark>

* MoonPay

onst exchangeTxnParams: ExchangesApiCreateExchangeRequest = { createExchangeAPIRequest: { provider: 'moonpay', type: 'offramp', wallet\_address: '0xqw2...', // L2 wallet widget: { theme: 'light' }, }, };

const exchangeTxnResponse = await imxClient.createExchange(exchangeTxnParams);

* Layerswap

```
const exchangeTxnParams: ExchangesApiCreateExchangeRequest = {
  createExchangeAPIRequest: {
    provider: 'layerswap',
    type: 'offramp',
    wallet_address: '0xqw2...', // L2 wallet
    widget: { theme: 'light' },
  },
};

const exchangeTxnResponse = await imxClient.createExchange(exchangeTxnParams);
```

After creating a transaction successfully, you will be provided with the specified provider's widget URL to be rendered where users can proceed with entering transfer details.

#### 3. Get transaction details[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#3-get-transaction-details) <a href="#id-3-get-transaction-details" id="id-3-get-transaction-details"></a>

📚API REFERENCE

* <mark style="color:blue;">getExchange</mark>

📚SDK REFERENCE

* <mark style="color:blue;">getExchange</mark>

Please consider checking the transaction status in a polling fashion in the background.

```
const transactionDetails = await imxClient.getExchange({
  id: exchangeTxnResponse.id,
});
```

#### 3. Get transaction details[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#3-get-transaction-details) <a href="#id-3-get-transaction-details" id="id-3-get-transaction-details"></a>

📚API REFERENCE

* <mark style="color:blue;">getExchange</mark>

📚SDK REFERENCE

* <mark style="color:blue;">getExchange</mark>

Please consider checking the transaction status in a polling fashion in the background.

```
const transactionDetails = await imxClient.getExchange({
  id: exchangeTxnResponse.id,
});
```

#### 4. Generate signers[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#4-generate-signers) <a href="#id-4-generate-signers" id="id-4-generate-signers"></a>

Initiating an off-ramp request for a user requires a user's signature, so your application will need to create signers. See the guide on <mark style="color:blue;">how to generate signers</mark>.

#### 5. Initiate the off-ramp request[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#5-initiate-the-off-ramp-request) <a href="#id-5-initiate-the-off-ramp-request" id="id-5-initiate-the-off-ramp-request"></a>

📚API REFERENCE

* <mark style="color:blue;">getExchangeSignableTransfer</mark>
* <mark style="color:blue;">createExchangeTransfer</mark>

📚SDK REFERENCE

* <mark style="color:blue;">exchangeTransfer</mark>

Before initiating the off-ramp request, check that the transaction details have been fetched (see <mark style="color:blue;">Step 3</mark>).

Once the details are fetched and status is `waitingPayment`, initiate the request:

```
const exchangeTransferParams: UnsignedExchangeTransferRequest = {
  type: transactionDetails.data.from_currency, // "ETH"
  amount: transactionDetails.data.from_amount, // "0.001"
  transactionID: transactionDetails.id,
  receiver: transactionDetails.provider_wallet_address,
};

const exchangeTransferResponse = await imxClient.exchangeTransfer(
  walletConnection,
  exchangeTransferParams
);
```

It will prompt the user to sign the request to proceed with the transaction.

#### 6. Verify the transaction status[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#6-verify-the-transaction-status) <a href="#id-6-verify-the-transaction-status" id="id-6-verify-the-transaction-status"></a>

See <mark style="color:blue;">3. Verify the transaction status</mark> in the on-ramp guide.

### API[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#api) <a href="#api" id="api"></a>

#### On-ramp endpoints:[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#on-ramp-endpoints) <a href="#on-ramp-endpoints" id="on-ramp-endpoints"></a>

| Step | Description                   | API endpoint                                    |
| ---- | ----------------------------- | ----------------------------------------------- |
| 1    | Create the on-ramp request    | <mark style="color:blue;">createExchange</mark> |
| 2    | Verify the transaction status | <mark style="color:blue;">getExchange</mark>    |

#### Off-ramp endpoints:[​](https://docs.x.immutable.com/docs/x/how-to-enable-on-off-ramps#off-ramp-endpoints) <a href="#off-ramp-endpoints" id="off-ramp-endpoints"></a>

| Step | Description                                                                   | API endpoint                                                 |
| ---- | ----------------------------------------------------------------------------- | ------------------------------------------------------------ |
| 1    | Create the off-ramp request                                                   | <mark style="color:blue;">createExchange</mark>              |
| 2    | Get transaction details                                                       | <mark style="color:blue;">getExchange</mark>                 |
| 3    | Get the transaction details to be signed when initiating the off-ramp request | <mark style="color:blue;">getExchangeSignableTransfer</mark> |
| 4    | Initiate the off-ramp request                                                 | <mark style="color:blue;">createExchangeTransfer</mark>      |

[<br>](https://docs.x.immutable.com/docs/x/how-to-enable-deposits-withdrawals)
