Sponsor gas
Gas fees are a significant barrier to entry for new users of your app. With Smart Wallets you can remove this barrier by sponsoring gas fees for transactions via the Gas Manager.
How it works
When a user requests gas sponsorship using a configured policy, the policy engine will determine if that transaction is eligible for sponsorship. If eligible, when the user sends the transaction the Gas Manager will pay for the gas fee upfront. The Gas Manager will make a note of the sponsored cost and bill the sponsoring developer in fiat.
Prerequisites
- API key from your dashboard
- A gas sponsorship policy.
Implementation
React
JavaScript
API
Use the useSendCalls
hook to sponsor gas for a transaction.
The gas sponsorship policy ID can be configured:
- In the
AlchemyAccountProvider
component configuration. Used by default if configured. - In the
paymasterService
capabilitiespolicyId
parameter. Overrides the component configuration.
Prerequisites
See the useSendCalls
SDK reference for parameter descriptions.
Advanced
Usage with prepare calls
Gas sponsorship also works with the prepare calls methods in the various frameworks. Usage of the capability will be the same as when using send calls. It is recommended to use prepare calls if you want to inspect the prepared call prior to prompting the user for signature.
React
JavaScript
API
See the usePrepareCalls
react
hook
Multiple policy IDs
Developers can configure multiple policy IDs for use in gas sponsorship. The
backend will choose the first policy ID that where the transaction is eligible
for sponsorship. This is done by passing an array of policy IDs instead of a
single policy ID to the sponsor gas capability. See the wallet_prepareCalls
API
parameters
for reference to the paymasterService.policyIds
parameter.
Next steps
Build more:
Troubleshooting: