<VersionWarning version="0.1" />

# sponsorUserOperation

:::warning
The Pimlico paymaster actions in permissionless.js only work with the v2 Pimlico API. The v1 API for paymasters is deprecated and will be removed in the future.

This version, instead of simply signing over the passed-in User Operation, estimates the gas values for the User Operation and then signs over the estimated gas values, returning not only the `paymasterAndData` but also the `preVerificationGas`, `verificationGasLimit`, and `callGasLimit`.
:::

Estimates the gas values for the User Operation and sponsors the operation with the new gas values.

## Usage

:::code-group
```ts [example.ts]
import { pimlicoPaymasterClient } from "./client"

const sponsorResult = await pimlicoPaymasterClient.sponsorUserOperation({
    userOperation: {
        sender: "0x0C123D90Da0a640fFE54a2359D159629065775C5",
        nonce: 3n,
        callData: "0x18dfb3c7000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d2f598c826429eee7c071c02735549acd88f2c09000000000000000000000000d2f598c826429eee7c071c02735549acd88f2c090000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000043a4eacb7839f202d9cab465dbdd77d4fabe0a1800000000000000000000000000000000000000000000000003782dace9d90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000982e148216e3aa6b38f9d901ef578b5c06dd750200000000000000000000000000000000000000000000000005d423c655aa000000000000000000000000000000000000000000000000000000000000",
        maxFeePerGas: 113000000n,
        maxPriorityFeePerGas: 113000100n,
        signature: "0xf1513a8537a079a4d728bb87099b2c901e2c9034e60c95a4d41ac1ed75d6ee90270d52b48af30aa036e9a205ea008e1c62b317e7b3f88b3f302d45fb1ba76a191b"
    },
    sponsorshipPolicyId: "sp_crazy_kangaroo" // optional, only if using Pimlico sponsorship policies
})
/**
 * {
    "paymaster": "0xe3dc822D77f8cA7ac74c30B0dfFEA9FcDCAAA321",
    "paymasterVerificationGasLimit": 93823n,
    "paymasterPostOpGasLimit": 134849n,
    "paymasterData": "000000000000000000000000000000000000000000000000000000006514ac7d000000000000000000000000000000000000000000000000000000000000000071eee8c38559ef6872351c16a312cefbc545344a3f7cc1b910d059a0d5c613012763e6b1ce31080a975ddcba12817305a62a322e3ec8f106bd2181b0fd1391cf1c",
    "preVerificationGas": 61230n,
    "verificationGasLimit": 93823n,
    "callGasLimit": 134849n
   }
 */
```

```ts [client.ts]
import { createClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { ENTRYPOINT_ADDRESS_V07 } from 'permissionless'
import { pimlicoPaymasterActions } from 'permissionless/actions/pimlico'

export const pimlicoPaymasterClient = createClient({ 
  chain: mainnet,
  transport: http("https://api.pimlico.io/v2/sepolia/rpc?apikey=YOUR_API_KEY_HERE")
}).extend(pimlicoPaymasterActions(ENTRYPOINT_ADDRESS_V07))
```
:::

## Returns

* **Type:** `SponsorUserOperationReturnType`

The estimated gas values for the User Operation and the paymaster related data that includes the Pimlico paymaster address and Pimlico's paymaster signature.

## Parameters

### userOperation

* **Type:** `UserOperation`

The User Operation object.

### sponsorshipPolicyId (optional)

* **Type:** `string`

The ID of the [sponsorship policy](https://dashboard.pimlico.io/sponsorship-policies) to use. If used, this call will error if the policy is not willing to sponsor this user operation. It is recommended to use pm\_validateSponsorshipPolicies before calling this method.

## JSON-RPC Method

[`pm_sponsorUserOperation`](/references/paymaster/verifying-paymaster/endpoints#pm_sponsoruseroperation-v2)
