Currency handlers
The currency handlers let a Live App list the cryptocurrencies and tokens that the connected wallet supports. The Wallet API server forwards each request to the wallet, which decides what to return.
Method IDs
| Method ID | Direction | Wallet handler required? | Purpose |
|---|---|---|---|
currency.list | Live App → Wallet | yes | List the currencies that the wallet supports, optionally filtered by ID. |
The Live App must declare currency.list in the permissions of its manifest. The server rejects calls to methods that are not in the permission list.
currency.list
Returns the currencies that the wallet handler provides.
Parameters
The params object is optional.
| Parameter | Type | Required | Notes |
|---|---|---|---|
currencyIds | string[] | no | Currency IDs to filter on. The server passes this value to the wallet handler without changing it. |
Behavior
The server validates params, then calls the wallet handler currency.list with { currencyIds }. The server does not filter the result itself. The wallet handler applies currencyIds and returns the Currency objects.
Result
{
currencies: Currency[]
}A Currency has one of two shapes, selected by the type field.
CryptoCurrency
| Field | Type | Required | Notes |
|---|---|---|---|
type | "CryptoCurrency" | yes | Discriminator. |
id | string | yes | Currency ID, for example bitcoin. |
name | string | yes | Display name. |
ticker | string | yes | Ticker symbol. |
color | string | yes | Brand color, for example #ffae35. |
decimals | number | yes | Number of decimals of the currency unit. |
family | string | yes | Coin family, for example bitcoin or ethereum. |
categories | string[] | no | Categories assigned to the currency. |
TokenCurrency (ERC20)
| Field | Type | Required | Notes |
|---|---|---|---|
type | "TokenCurrency" | yes | Discriminator. |
id | string | yes | Token ID. |
name | string | yes | Display name. |
ticker | string | yes | Ticker symbol. |
color | string | yes | Brand color. |
decimals | number | yes | Number of decimals of the token unit. |
parent | string | yes | ID of the parent currency. |
standard | "ERC20" | yes | Token standard. ERC20 is the only value. |
contract | string | yes | Contract address of the token. |
categories | string[] | no | Categories assigned to the currency. |
Errors
The server wraps each error in an RpcError.
| Condition | Error |
|---|---|
currencyIds is not an array of strings | RpcError with code INVALID_PARAMS (-32602). |
| The method is not in the Live App permissions | RpcError with code SERVER_ERROR (-32000). data.code is PERMISSION_DENIED. |
The wallet does not register a currency.list handler | RpcError with code SERVER_ERROR (-32000). data.code is NOT_IMPLEMENTED_BY_WALLET. |
Example
Register the wallet handler on the server. This example comes from the standard profile of the Simulator:
server.setHandler("currency.list", ({ currencyIds }) => {
if (currencyIds && currencyIds.length > 0) {
return currencies.filter((currency) => currencyIds.includes(currency.id));
}
return currencies;
});See also
- Account handlers: list and select the user’s accounts
- Currency module (client): the client-side counterpart
- How to use the Wallet API Server with a constructor: register wallet handlers on a server
currency.listsource andCurrencyListschema.