# Conditional Gas Sponsorship

> Step-by-step guide to sponsor gas for select transactions and users.

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

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:

```json
{
  "userOperation": {}, // structure depends on EntryPoint version
  "policyId": "",
  "chainId": "",
  "webhookData": ""
}
```

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

```json
{
  "approved": true // true to sponsor the tx, false to reject it
}
```

### 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.

Create a policy via the [Gas Manager dashboard](https://dashboard.alchemy.com/gas-manager/policy/create/?a=api-docs) or the [Create policy API](https://www.alchemy.com/docs/wallets/api/gas-manager-admin-api/admin-api-endpoints/create-policy).

### 3. Get Gas Manager's signature

<Info>
  **\[Recommended]** Use the [SDK](https://www.alchemy.com/docs/wallets) to
  create and use wallets. The SDK handles all complexity for you, making
  development faster and easier.
</Info>

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`](/docs/wallets/api-reference/bundler-api/bundler-api-endpoints/eth-send-user-operation). The Gas Manager will pay for the gas of the userOp when it is mined.