# Backend

## Endpoints needed for Buy

In order to communicate with Ledger’s backend, you must provide standardised APIs for Ledger's Buy aggregator services to call.

> **Note:** You will find all the information regarding the Buy endpoints <a href="./redoc-api" target="_blank">here</a>.

There are 4 endpoints needed for the Buy integration:

- To get the list of available fiat, country, payment, method and amount: [/capabilities](./redoc-api#operation/getCapabilities).
- To get the list of available crypto-currencies: [/crypto-currenciess](./redoc-api#operation/getCrypto-currencies).
- To get the crypto amount that the user should expect -after all fees are deducted - as a payment for the given fiat amount: [/quotes](./redoc-api#operation/getQuote).
- To get the URL of the on-ramp widget to which the user will be redirected. [/buy-redirect](./redoc-api#operation/buy-redirect).

### Ledger IDs mapping

To comply with our integration policies, the LedgerId format must be used (by your `/crypto-currencies` endpoint) and accepted (by your `/quote` endpoint and widgetURL) to accurately identify tokens and coins.

You can refer to [this API](https://crypto-assets-service.api.ledger.com/v1/currencies?output=id,name,ticker,contract_address,blockchain_name) to obtain ledger IDs. You can use the `search` parameter to find a specific coin or token. For instance, to search for USDT, you can use this [request](https://crypto-assets-service.api.ledger.com/v1/currencies?output=id,name,ticker,contract_address,blockchain_name\&search=USDT). The API returns paginated results: to access the next pages, include `cursor=<value of the "X-Ledger-Next" header>` in your request. Further information is available in the response headers.

Example: let's say your support AAVE on Ethereum mainnet. The LedgerID for AAVE on Ethereum is `ethereum/erc20/aave` (as we can see [here](https://crypto-assets-service.api.ledger.com/v1/currencies?output=id,name,ticker,contract_address,blockchain_name\&search=AAVE)). This means:

- Your `/crypto-currencies` endpoint must include `ethereum/erc20/aave` in its response (along with the other coins/tokens you support), so we know that you support AAVE on Ethereum.
- Your `/quote` endpoint must accept `ethereum/erc20/aave` as a value for the `to` parameter.
- Your widgetURL must accept `ethereum/erc20/aave` as a value for the `to` parameter.

[//]: # "Info needed to be exchange with the provider, but not out loud publicly"

[//]: # "**IP address checking** "

[//]: # "Additionally, we also need a way to know if a user will be able to perform a coin swap given his IP."

[//]: # "Our back-end can adapt to how you decide to do this, but we recommend you use a dedicated endpoint. Our back-end will send the user’s IP address to that endpoint, without logging it. In response, your endpoint should tell us if the trade is accepted or rejected."
