- Dollar to cent (USD 25.34 becomes 2534 cents)
- Bitcoin to satoshi (BTC 0.248917 becomes 24891700 satoshis)
- Ethereum to wei (ETH 0.189207535698279 becomes 189207535698279000 wei)
precise_amount and include precision so Blnk can derive the human-readable amount in responses.
Alternatively, you can pass a float in amount and let Blnk convert it to an integer using precision.
Determining your precision value
Follow these steps to calculate the best precision value for an asset class:Identify the smallest possible unit of the asset.
For example, the smallest unit for USD is $0.01 (1 cent), and for BTC, it’s 0.00000001 (1 satoshi).
Convert this smallest unit into an integer.
To do this, multiply the smallest unit by a factor that results in a whole number. For instance:
- For USD, multiply 0.01 by 100 to get 1 (since 100 cents makes a dollar).
- For BTC, multiply 0.00000001 by 100,000,000 to get 1 (since 100 million satoshis makes 1 BTC).
Use the multiplication factor as your precision value.
The number you used to convert the smallest unit to an integer becomes the precision value. In the examples above:
- USD precision value: 100
- BTC precision value: 100,000,000
Fiat currencies and their precision values
151 fiat currencies and precision values.
Applying precision
You can apply precision to amounts in your ledger in one of two ways.- Use
precise_amount(recommended) to pass the smallest unit directly, or - Pass a float in
amountand let Blnk convert it usingprecision.
- Using precise amount
- Using amount
Available in version 0.10.1 or later
precise_amount, and include the corresponding precision value.Blnk stores precise_amount as the ledger integer and returns the human-readable amount in responses (amount = precise_amount / precision).- Convert the amount to its smallest unit. Learn how
- Enter this value directly into the
precise_amountfield of your request. - Include the corresponding
precisionvalue.
| Field | Type | Description |
|---|---|---|
precise_amount | Integer | The transaction value in its smallest unit (e.g. 75023 cents for USD 750.23). |
precision | Number | The precision value (e.g. 100 converts USD to cents) |
Response
precise_amount with multiple sources or destinations, use precise_distribution instead of distribution for fixed amounts in your sources or destinations array.Percentages ("10%") and the remainder ("left") still use distribution.Example with precise_distribution
Important considerations
-
amountandprecise_amountcannot be passed simultaneously when recording a transaction. Preferprecise_amountfor consistency across your integration. - Ensure that your precision value converts the target amount to the lowest unit possible for its asset class. For example, while 100 works for most fiat currencies, it is not advisable to use it for cryptocurrencies like Bitcoin or Ethereum.
-
Be consistent with how precision is applied in your application. Transactions with the same
currencyshould always have the same precision applied to their amounts. -
Balance fields are integers in minor units. Core does not return
precisionon balances. To display an amount, divide by the precision you use for that currency (100000 / 100= $1,000.00). - Regularly review and audit your ledger to ensure that precision is applied consistently and correctly.
Error handling
Structured errors are available from Blnk Core 0.15.0 and later.
400 TXN_VALIDATION_ERROR when the amount fields in your request fail validation.
- Missing amount fields
- Both fields exist
- 15-digit limit
Neither
amount nor precise_amount is set:400 Bad Request