|
| 1 | +--- |
| 2 | +title: Conditional sponsorship rules |
| 3 | +description: Control gas sponsorship with policy limits and custom webhook rules |
| 4 | +slug: wallets/transactions/sponsor-gas/conditional-sponsorship-rules |
| 5 | +--- |
| 6 | + |
| 7 | +Conditional sponsorship gives you precise control over **who** gets sponsored and **which transactions** you pay for. |
| 8 | + |
| 9 | +Use it to: |
| 10 | + |
| 11 | +* Protect your budget with hard spend caps |
| 12 | +* Prioritize high-value users and actions |
| 13 | +* Prevent abuse with allowlists, blocklists, and custom logic |
| 14 | + |
| 15 | +## Ways to configure sponsorship rules |
| 16 | + |
| 17 | +You can configure the same policy logic in two ways: |
| 18 | + |
| 19 | +1. **Dashboard**: Create or edit a Gas Manager policy in the [Alchemy dashboard](https://dashboard.alchemy.com/gas-manager/policy/create) |
| 20 | +2. **Admin API**: Create or update policies programmatically with the [Gas Manager Admin API](/wallets/gas-manager-admin-api/gas-manager-admin-api-endpoints/gas-manager-admin-api-endpoints) |
| 21 | + |
| 22 | +Most teams start in the dashboard, then move to API-based management for automation. |
| 23 | + |
| 24 | +## Built-in policy limits |
| 25 | + |
| 26 | +Use built-in limits when you want fast setup without maintaining backend logic. |
| 27 | + |
| 28 | +You can combine these controls in one policy: |
| 29 | + |
| 30 | +* **Time-bounded policies**: Only sponsor during a specific start/end window |
| 31 | +* **Per-user spend limits**: Cap sponsorship spend per wallet/user |
| 32 | +* **Per-transaction spend limits**: Cap sponsorship per transaction |
| 33 | +* **Global max spend**: Set a hard maximum spend for the full policy |
| 34 | +* **Max transactions per user**: Limit number of sponsored transactions per user |
| 35 | +* **Sender allowlist / blocklist**: Explicitly allow or deny sponsorship for selected senders |
| 36 | + |
| 37 | +These limits are ideal for growth campaigns, onboarding credits, and controlled rollouts. |
| 38 | + |
| 39 | +## Custom rules with webhooks |
| 40 | + |
| 41 | +For advanced use cases, add a webhook so your server can approve or reject sponsorship requests in real time. |
| 42 | + |
| 43 | +Examples: |
| 44 | + |
| 45 | +* Sponsor only swaps |
| 46 | +* Sponsor only transactions that touch your contracts |
| 47 | +* Sponsor only high-ROI users (for example, power users) |
| 48 | +* Sponsor users with proof-of-humanity checks |
| 49 | + |
| 50 | +### How webhook-based sponsorship works |
| 51 | + |
| 52 | +When a sponsorship request is made, Gas Manager sends a `POST` request to your webhook. |
| 53 | + |
| 54 | +Your server evaluates the request and returns whether to approve sponsorship. |
| 55 | + |
| 56 | +#### Request payload |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "userOperation": {}, |
| 61 | + "policyId": "", |
| 62 | + "chainId": "", |
| 63 | + "webhookData": "" |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +Payload fields: |
| 68 | + |
| 69 | +* `userOperation`: UserOperation payload (shape depends on EntryPoint version) |
| 70 | +* `policyId`: Policy ID receiving the sponsorship request |
| 71 | +* `chainId`: Chain ID for the request |
| 72 | +* `webhookData` (optional): Additional app data, such as user attestations |
| 73 | + |
| 74 | +#### Expected webhook response |
| 75 | + |
| 76 | +Return HTTP `200` and: |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "approved": true |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +Set `approved` to: |
| 85 | + |
| 86 | +* `true` to sponsor gas |
| 87 | +* `false` to reject sponsorship |
| 88 | + |
| 89 | +### Configure webhook rules on your policy |
| 90 | + |
| 91 | +In your policy's **Custom Rules** section, set: |
| 92 | + |
| 93 | +* `webhookUrl` (required): Endpoint Gas Manager calls for eligibility |
| 94 | +* `approveOnFailure` (required, default `false`): If `true`, sponsorship is approved when webhook errors or times out |
| 95 | + |
| 96 | +In the Admin API, this configuration is represented as: |
| 97 | + |
| 98 | +```json |
| 99 | +{ |
| 100 | + "webhookRules": { |
| 101 | + "webhookUrl": "https://your-server.com/sponsor-gas", |
| 102 | + "approveOnFailure": false |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +## Recommended setup pattern |
| 108 | + |
| 109 | +For most teams, the best approach is: |
| 110 | + |
| 111 | +1. Start with built-in limits for immediate spend protection |
| 112 | +2. Add webhook rules for business-specific checks |
| 113 | +3. Decide your failure mode (`approveOnFailure`) based on risk tolerance: |
| 114 | + * Prefer uptime: set to `true` |
| 115 | + * Prefer strict control: set to `false` |
| 116 | + |
| 117 | +## Next steps |
| 118 | + |
| 119 | +* [Full sponsorship implementation](/wallets/transactions/sponsor-gas) |
| 120 | +* [Gas Manager Admin API endpoints](/wallets/gas-manager-admin-api/gas-manager-admin-api-endpoints/gas-manager-admin-api-endpoints) |
0 commit comments