You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/relayer/guides/stellar-sponsored-transactions-guide.mdx
+44-28Lines changed: 44 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,8 @@ Stellar Sponsored Transactions (also known as gasless transactions) allow users
15
15
16
16
The relayer handles the complexity of fee conversion, token swaps, and XLM fee payment, while users simply pay in their preferred token.
17
17
18
+
For additional context on fee abstraction in Soroban smart contracts, see [fee abstraction on stellar contracts](/stellar-contracts/fee-abstraction)
19
+
18
20
## Prerequisites
19
21
20
22
- A running OpenZeppelin Relayer instance
@@ -352,24 +354,7 @@ Supported operation types:
352
354
353
355
Soroban Gas Abstraction extends the sponsored transaction concept to Soroban smart contracts. Instead of requiring users to hold XLM for contract invocation fees, users can pay in any Soroban token (e.g., a USDC Soroban token contract). This is powered by a **FeeForwarder smart contract** that wraps the user's contract call with fee collection logic.
354
356
355
-
**How it differs from Classic Stellar Sponsored Transactions:**
356
-
357
-
| Aspect | Classic Stellar | Soroban Gas Abstraction |
|**Authorization**| Standard transaction signing | User signs a `SorobanAuthorizationEntry`|
363
-
|**Submission**| Relayer wraps in fee-bump envelope | Relayer injects signed auth entries and submits directly |
364
-
365
-
### Prerequisites
366
-
367
-
- A running OpenZeppelin Relayer instance
368
-
- A Stellar relayer configured with `"fee_payment_strategy": "user"`
369
-
- A deployed **FeeForwarder contract** on the target network. [Check the OpenZeppelin contract here](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/fee-abstraction)
370
-
- The `STELLAR_TESTNET_FEE_FORWARDER_ADDRESS` or `STELLAR_MAINNET_FEE_FORWARDER_ADDRESS` environment variable set to the FeeForwarder contract address
- Sufficient XLM balance in the relayer account for network fees
357
+
For additional context on the FeeForwarder contract and fee abstraction in Soroban smart contracts, see the [fee abstraction documentation](/stellar-contracts/fee-abstraction).
373
358
374
359
### Configuration
375
360
@@ -411,6 +396,31 @@ Configure the relayer with Soroban token contracts in the `allowed_tokens` list.
411
396
}
412
397
```
413
398
399
+
**How it differs from Classic Stellar Sponsored Transactions:**
400
+
401
+
| Aspect | Classic Stellar | Soroban Gas Abstraction |
|**Authorization**| Standard transaction signing | User signs a `SorobanAuthorizationEntry`|
407
+
|**Submission**| Relayer wraps in fee-bump envelope | Relayer injects signed auth entries and submits directly |
408
+
409
+
### Prerequisites
410
+
411
+
- A running OpenZeppelin Relayer instance
412
+
- A Stellar relayer configured with `"fee_payment_strategy": "user"`
413
+
- A deployed **FeeForwarder contract** on the target network. [Check the OpenZeppelin contract here](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/fee-abstraction)
414
+
- The `STELLAR_TESTNET_FEE_FORWARDER_ADDRESS` or `STELLAR_MAINNET_FEE_FORWARDER_ADDRESS` environment variable set to the FeeForwarder contract address
415
+
-**Soroswap contract addresses configured** via environment variables (Router, Factory, and Native Wrapper). These are required for the relayer to get quotes and perform token swaps. See [Soroswap documentation](https://docs.soroswap.finance/) for how to find contract addresses
416
+
- Allowed tokens configured with Soroban token contract addresses (`C...` format). **The fee tokens you use must have liquidity pools on [Soroswap](https://app.soroswap.finance/)**, as the relayer uses Soroswap to get quotes and convert tokens to XLM
417
+
-**Trustlines** established for fee tokens:
418
+
- The **relayer account** must have a trustline to each fee token it accepts
419
+
- If testing with a **SAC (Stellar Asset Contract) token**, the **user account** must also have a trustline to the token. See the [Relayer SDK trustline example](https://github.com/OpenZeppelin/openzeppelin-relayer-sdk/tree/main/examples/relayers/stellar/src/sponsored/createTrustline.ts) for how to create trustlines
420
+
- Sufficient XLM balance in the relayer account for network fees
421
+
422
+
### Environment Variables
423
+
414
424
Set the required environment variables:
415
425
416
426
<Callout>
@@ -421,18 +431,20 @@ Set the required environment variables:
421
431
422
432
```bash
423
433
# Stellar FeeForwarder Contract Addresses
434
+
# Deploy your own or find the address from the OpenZeppelin stellar-contracts repository:
The Soroban gas abstraction flow uses the same endpoints as classic sponsored transactions but with key differences in the request/response payloads and an additional authorization signing step.
443
455
444
-
#### Step 1: Get Fee Quote
456
+
#### Step 1: Get Fee Quote (Optional)
445
457
446
-
Estimate the fee for a Soroban contract invocation in your preferred token.
458
+
This step is **optional and informational**. It allows you to estimate the fee cost before building the transaction, which is useful for displaying the expected cost to users. You can skip directly to Step 2 (Build) if you don't need a fee estimate upfront.
@@ -490,6 +502,10 @@ Prepare a Soroban transaction that wraps your contract call with the FeeForwarde
490
502
}
491
503
```
492
504
505
+
<Callouttype="warn">
506
+
The authorization entry has a **2-minute expiration window** (~24 ledgers at ~5 seconds each). This means you must sign and submit the transaction promptly after building it. If you are testing manually or your flow involves back-and-forth steps, be aware that the authorization may expire before submission. If your transaction fails with an expiration error, rebuild and re-sign the transaction.
507
+
</Callout>
508
+
493
509
**Response:**
494
510
495
511
The response includes a `user_auth_entry` field containing the Soroban authorization entry that the user must sign. This authorization entry authorizes the FeeForwarder contract to collect fees in the specified token on the user's behalf.
@@ -621,11 +637,11 @@ The contract's `forward()` function takes these parameters:
621
637
### Best Practices for Soroban Gas Abstraction
622
638
623
639
1.**Use the Quote endpoint first**: Always get a fee estimate before building to show users the expected cost, including the max fee with slippage
624
-
2.**Handle authorization expiration**: Authorization entries expire at a specific ledger. Rebuild if the authorization has expired
625
-
3.**Validate token contract addresses**: Ensure fee tokens use valid Soroban contract addresses (`C...` format, 56 characters)
626
-
4.**Monitor resource fees**: Soroban transactions have dynamic resource fees based on CPU instructions, storage reads/writes, and ledger entry access. The relayer applies a 15% buffer, but complex contract calls may need higher limits
627
-
5.**Set appropriate max fees**: Configure `max_allowed_fee` per token to prevent excessive fees during network congestion
628
-
6.**Configure the FeeForwarder address**: Ensure the correct FeeForwarder contract address is set via environment variables for each network
640
+
2.**Handle authorization expiration**: Authorization entries have a **2-minute expiration window**. Sign and submit promptly after building. If the authorization expires, rebuild and re-sign the transaction
641
+
4.**Validate token contract addresses**: Ensure fee tokens use valid Soroban contract addresses (`C...` format, 56 characters)
642
+
5.**Monitor resource fees**: Soroban transactions have dynamic resource fees based on CPU instructions, storage reads/writes, and ledger entry access. The relayer applies a 15% buffer, but complex contract calls may need higher limits
643
+
6.**Set appropriate max fees**: Configure `max_allowed_fee` per token to prevent excessive fees during network congestion
644
+
7.**Configure the FeeForwarder address**: Ensure the correct FeeForwarder contract address is set via environment variables for each network
0 commit comments