Use the Stellar Wallet Sponsorship Calculator to estimate the XLM requirements for wallets looking to use sponsored reserves and fee-bump transactions to cover account creation, transaction fees, trustlines, and more.
Sponsored reserves operations
Begin and end sponsorships
To create a sponsored reserve, you have to use a sandwich transaction that includes three operations.- The first operation: Begin Sponsoring Future Reserves initiates the sponsorship and requires the sponsoring account’s signature.
- The second operation: specifies what is being sponsored.
- The third operation: End Sponsoring Future Reserves, allows the sponsored account to accept the sponsorship and requires the sponsored account’s signature.
Revoke sponsorship
Allows the sponsoring account to remove or transfer sponsorships of existing ledgerEntries and signers. If the ledgerEntry or signer is not sponsored, the owner of the ledgerEntry or signer can establish a sponsorship if it is the beneficiary of an is-sponsoring-future-reserves-for relationship. Operation logic- Entry/signer is sponsored
- Source account is currently the beneficiary of a is-sponsoring-future-reserves-for relationship
- Transfer sponsorship of entry/signer from source account to the account that is-sponsoring-future-reserves-for source account
- Source account is not the beneficiary of a is-sponsoring-future-reserves-for relationship
- Remove the sponsorship from the entry/signer
- Source account is currently the beneficiary of a is-sponsoring-future-reserves-for relationship
- Entry/signer is not sponsored
- Source account is currently the beneficiary of a is-sponsoring-future-reserves-for relationship
- Establish sponsorship between entry/signer and the account that is-sponsoring-future-reserves-for source account
- Source account is not the beneficiary of a is-sponsoring-future-reserves-for relationship
- No-Op
- Source account is currently the beneficiary of a is-sponsoring-future-reserves-for relationship
Effect on minimum balance
Once sponsorships are introduced, the minimum balance calculation is: (2 +numSubEntries + numSponsoring - numSponsored) * baseReserve.
Selling liabilities are not part of the minimum balance. They reduce the balance available above it: available balance = balance - minimum balance - liabilities.selling.
When account A is sponsoring future reserves for account B, any reserve requirements that would normally accumulate on B will instead accumulate on A, shown in numSponsoring. The fact that these reserves are being provided by another account will be reflected on B in numSponsored, which cancels out the increase in numSubEntries, keeping the minimum balance unchanged for B.
When a sponsored entry or subentry is removed, numSponsoring is decreased on the sponsoring account and numSponsored is decreased on the sponsored account.
Because sponsorship can cover an account’s own base reserves as well as its subentries, a brand-new account can be created with a startingBalance of 0: wrap the CreateAccount operation in a BeginSponsoringFutureReserves/EndSponsoringFutureReserves sandwich (as in the examples below) and the sponsor carries the two base reserves so the account never has to hold the minimum balance itself.
To learn more about minimum balance requirements, see our section on Lumens.
Effect on claimable balances
All claimable balances are sponsored through built-in logic in the claimable balance operations. The account that creates the claimable balance pays the base reserve to get the claimable balance on the ledger. When the claimable balance is claimed by the claimant(s), the claimable balance is removed from the ledger, and the account that created it gets the base reserve back. Read more about claimable balances in our Claimable Balances guide.Examples
Each of the following examples builds on itself, referencing variables from previous snippets. The following examples will demonstrate:- Sponsor trustline creation for another account
- Transfer the sponsorship responsibility from one account to another
- Revoke the sponsorship by an account entirely
SignAndSend(…) method (defined below) which creates and submits a transaction with the proper parameters and basic error-checking.
Preamble
We’ll start by including the boilerplate of account and asset creation.1. Sponsoring trustlines
Now, let’s sponsor trustlines for Account A. Notice how theCHANGE_TRUST operation is sandwiched between the begin and end sponsoring operations and that all relevant accounts need to sign the transaction.
Sponsoring a single trustline
Sponsoring a single trustline
Two accounts sponsoring different assets for a single account
Two accounts sponsoring different assets for a single account
2. Transferring sponsorship
Suppose that now Signer 1 wants to transfer the responsibility of sponsoring reserves for the trustline to Sponsor 2. This is accomplished by sandwiching the transfer between theBEGIN/END_SPONSORING_FUTURE_RESERVES operations. Both of the participants must sign the transaction, though either can submit it.
An intuitive way to think of a sponsorship transfer is that the very act of sponsorship is being sponsored by a new account. That is, the new sponsor takes over the responsibilities of the old sponsor by sponsoring a revocation.
3. Sponsorship revocation
Finally, we can demonstrate complete revocation of sponsorships. Below, Signer 2 removes themselves from all responsibility over the two asset trustlines. Notice that Account A is not involved at all, since revocation should be performable purely at the sponsor’s discretion.Sponsorship Source Accounts
When it comes to the SourceAccount fields of the sponsorship sandwich, it’s important to refer to the wisdom of CAP-33:This relation is initiated bySince the source account defaults to the transaction submitter when omitted, this field needs always needs to be set for either theBeginSponsoringFutureReservesOp, where the sponsoring account is the source account, and is terminated byEndSponsoringFutureReserveOp, where the sponsored account is the source account.
Begin or the End.
For example, the following is an identical expression of the earlier Golang example of sponsoring a trustline, just submitted by the sponsor (Sponsor 1) rather than the sponsored account (Account A). Notice the differences in where SourceAccount is set:
Other examples
If you’d like other examples or want to view a more-generic pseudo-code breakdown of these sponsorship scenarios, you can refer to CAP-33 directly.Footnote
For the above examples, an implementation ofSignAndSend (Golang) and some (very) rudimentary error checking code (all languages) might look something like this: