Payment Currencies
The Payment Currencies API allows you to manage the different currencies your application accepts for payments. Each currency is linked to a specific payment method and defines properties such as its name, symbol, and decimal precision.
This is a core resource that is referenced by other objects, such as Prices.
The Payment Currency Object#
A PaymentCurrency object contains detailed information about a supported currency.
Attribute | Type | Description |
|---|---|---|
|
| Unique identifier for the currency object. |
|
| The ID of the payment method this currency is associated with. |
|
| Whether this currency is active and can be used for payments. |
|
|
|
|
| If |
|
| Indicates if this is a base currency for the associated payment method. |
|
| The full name of the currency (e.g., "Ethereum"). |
|
| A description of the currency. |
|
| A URL to an image or logo for the currency. |
|
| The currency symbol (e.g., "ETH"). |
|
| The number of decimal places the currency supports. |
|
| The maximum number of digits after the decimal point. |
|
| The minimum amount required for a single payment, as a string. |
|
| The maximum amount allowed for a single payment, as a string. |
|
| The contract address for token-based currencies, if applicable. |
|
| The type of currency. Can be |
|
| Configuration for the currency vault. Contains |
|
| A set of key-value pairs that you can attach to an object. |
|
| The timestamp of when the currency was created. |
|
| The timestamp of the last update to the currency. |
Create a Currency#
Creates a new payment currency that your application can accept.
Parameters
Name | Type | Description |
|---|---|---|
|
| Required. The full name of the currency. |
|
| Required. The ID of the payment method this currency belongs to. |
|
| Required. The currency's symbol. |
|
| Required. A URL for the currency's logo. |
|
| An optional description for the currency. |
|
| The number of decimal places. Defaults to |
|
| The type of currency. Can be |
|
| Whether the currency is active. Defaults to |
|
| The minimum payment amount. Defaults to |
|
| The maximum payment amount. Defaults to a very large number string. |
|
| The contract address for token-based currencies. |
Example
import payment from '@blocklet/payment-js';
async function createCurrency() {
try {
const currency = await payment.paymentCurrencies.create({
name: 'ArcBlock Token',
symbol: 'ABT',
logo: 'https://www.arcblock.io/images/abt-logo.png',
description: 'The native token of the ArcBlock platform.',
payment_method_id: 'pm_xxxxxxxxxxxx',
decimal: 18,
type: 'standard'
});
console.log('Currency created:', currency);
} catch (error) {
console.error('Error creating currency:', error);
}
}
createCurrency();Example Response
{
"id": "curr_1234567890",
"payment_method_id": "pm_xxxxxxxxxxxx",
"active": true,
"livemode": false,
"locked": false,
"is_base_currency": false,
"name": "ArcBlock Token",
"description": "The native token of the ArcBlock platform.",
"logo": "https://www.arcblock.io/images/abt-logo.png",
"symbol": "ABT",
"decimal": 18,
"maximum_precision": 8,
"minimum_payment_amount": "0",
"maximum_payment_amount": "10000000000000000000000000000",
"contract": null,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z",
"vault_config": null,
"type": "standard"
}Retrieve a Currency#
Retrieves the details of an existing payment currency.
Parameters
Name | Type | Description |
|---|---|---|
|
| Required. The unique identifier of the currency to retrieve. |
Example
import payment from '@blocklet/payment-js';
async function getCurrency(currencyId) {
try {
const currency = await payment.paymentCurrencies.retrieve(currencyId);
console.log('Retrieved currency:', currency.name);
} catch (error) {
console.error('Error retrieving currency:', error);
}
}
getCurrency('curr_1234567890');Example Response
{
"id": "curr_1234567890",
"payment_method_id": "pm_xxxxxxxxxxxx",
"active": true,
"livemode": false,
"locked": false,
"is_base_currency": false,
"name": "ArcBlock Token",
"description": "The native token of the ArcBlock platform.",
"logo": "https://www.arcblock.io/images/abt-logo.png",
"symbol": "ABT",
"decimal": 18,
"maximum_precision": 8,
"minimum_payment_amount": "0",
"maximum_payment_amount": "10000000000000000000000000000",
"contract": null,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z",
"vault_config": null,
"type": "standard"
}Update a Currency#
Updates the specified payment currency by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
Parameters
The first argument is the id of the currency to update. The second argument is an object containing the fields to update.
Name | Type | Description |
|---|---|---|
|
| The full name of the currency. |
|
| A description for the currency. |
|
| A URL for the currency's logo. |
|
| Whether the currency is active. |
|
| The minimum payment amount. |
|
| The maximum payment amount. |
|
| A set of key-value pairs to store with the currency. |
Example
import payment from '@blocklet/payment-js';
async function updateCurrency(currencyId) {
try {
const currency = await payment.paymentCurrencies.update(currencyId, {
description: 'An updated description for the native token of ArcBlock.'
});
console.log('Currency updated:', currency.description);
} catch (error) {
console.error('Error updating currency:', error);
}
}
updateCurrency('curr_1234567890');Example Response
{
"id": "curr_1234567890",
"payment_method_id": "pm_xxxxxxxxxxxx",
"active": true,
"livemode": false,
"locked": false,
"is_base_currency": false,
"name": "ArcBlock Token",
"description": "An updated description for the native token of ArcBlock.",
"logo": "https://www.arcblock.io/images/abt-logo.png",
"symbol": "ABT",
"decimal": 18,
"maximum_precision": 8,
"minimum_payment_amount": "0",
"maximum_payment_amount": "10000000000000000000000000000",
"contract": null,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T11:00:00.000Z",
"vault_config": null,
"type": "standard"
}List Currencies#
Returns a list of your payment currencies. The currencies are returned sorted by creation date, with the most recently created currencies appearing first.
Parameters
Name | Type | Description |
|---|---|---|
|
| The page number for pagination. Defaults to |
|
| The number of items per page. Defaults to |
|
| The order to sort the results by. Example: |
Example
import payment from '@blocklet/payment-js';
async function listCurrencies() {
try {
const currencyList = await payment.paymentCurrencies.list({ pageSize: 5 });
console.log(`Found ${currencyList.length} currencies:`);
currencyList.forEach(currency => {
console.log(`- ${currency.name} (${currency.symbol})`);
});
} catch (error) {
console.error('Error listing currencies:', error);
}
}
listCurrencies();Example Response
The list method returns an array of PaymentCurrency objects.
[
{
"id": "curr_1234567890",
"name": "ArcBlock Token",
"symbol": "ABT",
"active": true,
"livemode": false,
"logo": "https://www.arcblock.io/images/abt-logo.png"
},
{
"id": "curr_abcdefghij",
"name": "Ethereum",
"symbol": "ETH",
"active": true,
"livemode": false,
"logo": "https://example.com/eth_logo.png"
}
]Now that you know how to manage currencies, you can explore how to manage the Payment Methods they are associated with or how to use them in Prices.