It is sometimes helpful to prevent an account from going below a certain threshold balance. The save directive allows you to specify a minimum balance for an account, which will be deduced from the account available balance for the transaction.
In this transaction example, even if the account @merchants:1234 has an initial balance of [USD/2 500], the transaction will fail as the account post-transaction balance would otherwise be less than [USD/2 100].
Should additional source of funds is provided, the account will act as if its balance is [USD/2 100] less than it actually is:
Insufficient funds error#
When the requested amount exceeds the available balance (after applying save), the transaction fails with an INSUFFICIENT_FUND error.
Example: Account has [GBP/2 120], save [GBP/2 100], available = [GBP/2 20]
This fails because you're trying to send 30 but only 20 is available:
Using save with send [ASSET *]#
When using send [ASSET *] (send entire balance) with save, the behavior depends on the account balance:
Balance greater than save amount#
If the balance exceeds the saved amount, the transaction sends balance - saved_amount:
Result: A transaction of [GBP/2 20] is created (120 - 100 = 20).
Balance less than or equal to save amount#
If the balance is less than or equal to the saved amount, a transaction with amount 0 is created:
Result:
A transaction with 0 amount is still created and recorded in the ledger. This can be useful for audit purposes but may need to be filtered out in reporting.
Multiple source accounts with save#
When using multiple sources with save, funds are taken from the saved account up to its available limit, then completed from other sources:
Result:
@account_acontributes[USD/2 50](its available balance: 150 - 100)@account_bcontributes[USD/2 30](remainder needed)