> For the complete documentation index, see [llms.txt](https://docs.ees.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ees.xyz/guides/sponsor-jobs.md).

# Sponsor jobs

In this guide we will take you through an example of sponsoring a job using ees-sdk, viem and Typescript. Going forward it is assumed that ees-sdk is installed and setup like shown [here](/sdk.md).&#x20;

As a real example, we will in this guide show how to sponsor a [Socialsub](https://www.socialsub.xyz/) job for a recurring payment using execution module [0x00 RegularTimeInterval](/execution-modules/regulartimeinterval.md) and fee module [0x01 LinearAuction](/fee-modules/linearauction.md) on [Base Sepolia](https://sepolia.basescan.org). The Socialsub application is depoyed at address `0xe1efEA15fe277A360bd9bE3e8860Ce5c508Ca938`.&#x20;

The execution module input values we wish to sponsor has the following values:

| Solidity type | Name                   | Value     |
| ------------- | ---------------------- | --------- |
| `uint32`      | `cooldown`             | `2592000` |
| `uint40`      | `initialExecutionTime` | `0`       |

Similarly, the fee module input values we wish to sponsor:

| Solidity Type | Name                | Value                                        |
| ------------- | ------------------- | -------------------------------------------- |
| `address`     | `executionFeeToken` | `0x7139F4601480d20d43Fa77780B67D295805aD31a` |
| `uint256`     | `minExecutionFee`   | `0`                                          |
| `uint256`     | `maxExecutionFee`   | `10000`                                      |

Finally, the application input values for the job we wish to sponsor has the values:

| Solidity type | Name        | Value                                        |
| ------------- | ----------- | -------------------------------------------- |
| `address`     | `recipient` | `0x303cAE9641B868722194Bd9517eaC5ca2ad6e71a` |
| `uint256`     | `amount`    | `1000000`                                    |
| `address`     | `token`     | `0x7139F4601480d20d43Fa77780B67D295805aD31a` |
| `uint96`      | `tierId`    | `0`                                          |

First, we are going to import some functions and types from ees-sdk and viem:

```typescript
import { JobSpecification } from 'ees-sdk';
import { encodeAbiParameters } from 'viem';
```

To create a sponsor signature for the said specification, we are going to use the [`signJobSpecificationSponsor`](/sdk/sponsor-job.md) function which takes an object of type `JobSpecification`. Before creating the object, we have to specify a nonce and a deadline. If `reusableNonce` in the `JobSpecification` is true, then the signature can be reused to create multiple with this specification until the nonce is invalidated on-chain. Otherwise, the nonce will be consumed and the signature can only be used once. In the latter case, we should use a new nonce for each signature. The deadline specifies when the signature expires. In this example we will just use nonce 0 and the maximum uint256 value as deadline (no deadline in practice).

```typescript
const jobSpecification: JobSpecification = {
    nonce: 0n,
    deadline: BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),
    application: "0x7d337f7452fb892D7DAdfb4f7c02249DDAc41d4E",
    executionWindow: 1800, // 30 minutes
    zeroFeeWindow: 0,
    maxExecutions: 0,
    reusableNonce: false,
    sponsorFallbackToOwner: false,
    sponsorCanUpdateFeeModule: false,
    ignoreAppRevert: false,
    executionModule: "0x00",
    feeModule: "0x01",
    executionModuleInput: encodeAbiParameters(
      [
          {name: 'cooldown', type: 'uint32'},
          { name: 'initialExecutionTime', type: 'uint40' }
      ],
      [2592000, 0]
    ),
    feeModuleInput: encodeAbiParameters(
       [
          { name: 'executionFeeToken', type: 'address' },
          { name: 'minExecutionFee', type: 'uint256' },
          { name: 'maxExecutionFee', type: 'uint256' }
      ],
      ["0x7139F4601480d20d43Fa77780B67D295805aD31a", 0n, 10000n]
    ),
    applicationInput: encodeAbiParameters(
      [
          { name: 'recipient', type: 'address' },
          { name: 'amount', type: 'uint256' },
          { name: 'token', type: 'address' },
          { name: 'tierId', type: 'uint96' }
      ],
      ["0x303cAE9641B868722194Bd9517eaC5ca2ad6e71a", 1000000n, "0x7139F4601480d20d43Fa77780B67D295805aD31a", 0n]
    )
  }
```

Now we can utilize the `signJobSpecificationSponsor` function from ees-sdk:

```typescript
const signature: `0x${string}` = await eesSdk.signJobSpecificationSponsor(jobSpecification);
```

And voila, now we have successfully generated an EIP-712 signature which can be used as input to creating a job through the `JobManager` contract.

{% hint style="info" %}
**Tip:** In practice you can uniformly sample a random number between `0` and `2^256 - 1` for the nonce. Because the sample space is so large, the probability of generating two signatures with the same nonce is vanishingly small.
{% endhint %}

{% hint style="warning" %}
**Warning:** Be careful handling ERC-20 token amounts. The signed amounts are using full integer precision according to the number of decimals of the token. In this example, the `maxExecutionFee` of `10000` correspond to `0.01` in decimal form since the fee token uses 6 decimals in this example. Viem's `parseUnits` and `formatUnits` functions can be utilized to convert between the two formats.
{% endhint %}

{% hint style="danger" %}
**Careful**: Be sure to only sign job specifications with `reusableNonce=true` if you intend an unlimited number of users to be able to create jobs with this specification using you as sponsor.
{% endhint %}
