TheDocumentation Index
Fetch the complete documentation index at: https://docs.formance.com/llms.txt
Use this file to discover all available pages before exploring further.
overdraft directive lets you instruct the Numscript interpreter that an account post-transaction balance is allowed to be less than zero.
Unbounded
The overdraft directive allows for the account to go below zero without any limit, by using theunbounded keyword:
Bounded
The exact amount below zero at which the account is allowed to go can be specified by using theup to keyword with a monetary value:
The overdraft() function
When working with asset accounts that have negative balances, you can use theoverdraft() function to safely check balances and perform transactions atomically.
Overview
Theoverdraft() function returns the positive amount of overdraft when an account’s balance is negative, or 0 if the balance is positive. This is particularly useful when working with asset accounts, which by design have negative balances in Formance.
Usage
Here’s how to use the overdraft function:- If
@accounthas a balance of[USD/2 -50],$acc_overdraftwill be[USD/2 50] - If
@accounthas a balance of[USD/2 100],$acc_overdraftwill be[USD/2 0]
Enabling the experimental feature
To useoverdraft(), you need to enable two experimental features:
- The experimental rewrite feature
- The
experimental-overdraft-functionflag
Alternative: Using balance()
If you cannot use the experimental features, note that the standardbalance() function only works with non-negative balances and will fail if the account balance is negative.
overdraft() function instead.
Setting Overdrafts via API
In addition to specifying overdrafts in Numscript, you can also configure overdraft limits directly via the API when creating transactions.Using the transaction endpoint
When sending a transaction via the API, you can specify overdraft allowances in the script’svars section: