Conditional gas sponsorship

In this guide, you’ll learn how to enable conditional gas sponsorship to sponsor gas only for select transactions or users. Ex:

  • Sponsor gas only for swaps or txs that interact with your contracts.
  • Sponsor gas only for high-ROI users such as power users of your app or users with proof of humanity.

1. Create a Webhook

The webhook decides whether a given transaction should be sponsored. Every time you request gas sponsorship, the Gas Manager will make a POST request to your webhook. Your server responds with approval or rejection based on your custom rules.

Request Payload

  • userOperation: The userOp object.
  • policyId: The ID of your policy.
  • chainId: The ID of the network.
  • webhookData: Optional additional data you wish to include in the request, such as proof of humanity.

Here is an example request body:

1{
2 "userOperation": {}, // structure depends on EntryPoint version
3 "policyId": "",
4 "chainId": "",
5 "webhookData": ""
6}

Expected Result: Your endpoint should respond with 200 status code and the following JSON body:

1{
2 "approved": true // true to sponsor the tx, false to reject it
3}

2. Create a Gas Manager Policy

A gas manager policy defines which transactions (userOps) are eligible for gas sponsorship. To enable conditional gas sponsorship, you’ll need to fill in the Custom Rules section:

  • Custom rules: sponsor gas only for certain actions or users by making a request to your server to verify sponsorship eligibility. To enable, add the following details on your policy:

    • URL: the webhook URL the Gas Manager will make a POST request to every time you request gas sponsorship
    • Sponsor on error or timeout: when selected, the userOp will be sponsored in the event of an error or timeout.

You can create a policy via the Gas Manager dashboard or our Create policy API.

3. Get Gas Manager’s signature

[Recommended] Use our SDK to create and use wallets. The SDK handles all complexity for you, making development faster and easier.

Use the alchemy_requestGasAndPaymasterAndData endpoint to get the Gas Manager’s signature (paymaster and paymasterData). You’ll need to pass your policy id, the API key of the app associated with the policy, the userOp, and optional webhookData that will be passed to your webhook for decision-making. The Gas Manager will make a request to your webhook. If approved and the userOp satisfied any additional rules defined in the policy, the Gas Manager will return the signature.

4. Send the sponsored userOp

Once you get the paymaster and paymasterData fields, you can use them in your userOp when you call eth_sendUserOperation. The Gas Manager will pay for the gas of the userOp when it is mined.