> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Spend Permissions

export const GithubRepoCard = ({title, githubUrl}) => {
  return <a href={githubUrl} target="_blank" rel="noopener noreferrer" className="mb-4 flex items-center rounded-lg bg-zinc-900 p-4 text-white transition-all hover:bg-zinc-800">
      <div className="flex w-full items-center gap-3">
        <svg height="24" width="24" className="flex-shrink-0 dark:fill-white" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
          <path fill="currentColor" fillRule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />
        </svg>

        <div className="flex min-w-0 flex-grow flex-col">
          <span className="truncate text-base font-medium">{title}</span>
          <span className="truncate text-xs text-zinc-400">{githubUrl}</span>
        </div>

        <svg className="h-5 w-5 flex-shrink-0 text-zinc-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
        </svg>
      </div>
    </a>;
};

You can find the open-source contracts repository by clicking the button below:

<GithubRepoCard title="Spend Permissions" githubUrl="https://github.com/coinbase/spend-permissions" />

### Structs

#### `SpendPermission`

Defines the complete parameters of a spend permission.

<Warning>
  The fields of the `SpendPermission` structure must be strictly ordered as
  defined below.
</Warning>

| Field       | Type      | Description                                                                                |
| ----------- | --------- | ------------------------------------------------------------------------------------------ |
| `account`   | `address` | Smart account this spend permission is valid for.                                          |
| `spender`   | `address` | Entity that can spend `account`'s tokens.                                                  |
| `token`     | `address` | Token address (ERC-7528 native token address or ERC-20 contract).                          |
| `allowance` | `uint160` | Maximum allowed value to spend within each `period`.                                       |
| `period`    | `uint48`  | Time duration for resetting used `allowance` on a recurring basis (seconds).               |
| `start`     | `uint48`  | Timestamp this spend permission is valid starting at (unix seconds).                       |
| `end`       | `uint48`  | Timestamp this spend permission is valid until (unix seconds).                             |
| `salt`      | `uint256` | An arbitrary salt to differentiate unique spend permissions with otherwise identical data. |
| `extraData` | `bytes`   | Arbitrary data to include in the permission.                                               |

#### `PeriodSpend`

Describes the cumulative spend for the current active period.

| Field   | Type      | Description                              |
| ------- | --------- | ---------------------------------------- |
| `start` | `uint48`  | Start time of the period (unix seconds). |
| `end`   | `uint48`  | End time of the period (unix seconds).   |
| `spend` | `uint160` | Accumulated spend amount for period.     |

***

### Contract functions

#### `approve`

Approve a spend permission via a direct call from the `account`. Only callable by the `account` specified in the spend permission.

```solidity theme={null}
function approve(SpendPermission calldata spendPermission) external;
```

***

#### `approveWithSignature`

Approve a spend permission via a signature from the `account` owner. Compatible with [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492) signatures for automatic account creation if needed.

```solidity theme={null}
function approveWithSignature(SpendPermission calldata spendPermission, bytes calldata signature) external;
```

***

#### `spend`

Spend tokens using a spend permission, transferring them from the `account` to the `spender`. Only callable by the `spender` specified in the permission.

```solidity theme={null}
function spend(SpendPermission memory spendPermission, uint160 value) external;
```

***

#### `revoke`

Revoke a spend permission, permanently disabling its use. Only callable by the `account` specified in the spend permission.

```solidity theme={null}
function revoke(SpendPermission calldata spendPermission) external;
```

***

#### `revokeAsSpender`

Revoke a spend permission, permanently disabling its use. Only callable by the `spender` specified in the spend permission.

```solidity theme={null}
function revokeAsSpender(SpendPermission calldata spendPermission) external;
```

***

#### `getHash`

Generate a hash of a `SpendPermission` struct for signing, in accordance with [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md).

```solidity theme={null}
function getHash(SpendPermission memory spendPermission) public view returns (bytes32);
```

***

#### `isApproved`

Check if a spend permission is approved, regardless of whether the current time is within the valid time range of the permission.

```solidity theme={null}
function isApproved(SpendPermission memory spendPermission) public view returns (bool);
```

***

#### `isRevoked`

Check if a spend permission is revoked, regardless of whether the current time is within the valid time range of the permission.

```solidity theme={null}
function isRevoked(SpendPermission memory spendPermission) public view returns (bool);
```

***

#### `isValid`

Check if a spend permission is approved and not revoked, regardless of whether the current time is within the valid time range of the permission.

```solidity theme={null}
function isValid(SpendPermission memory spendPermission) public view returns (bool);
```

***

#### `getLastUpdatedPeriod`

Retrieve the `start`, `end`, and accumulated `spend` for the last updated period of a spend permission.

```solidity theme={null}
function getLastUpdatedPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);
```

***

#### `getCurrentPeriod`

Retrieve the `start`, `end`, and accumulated `spend` for the current period of a spend permission.
Reverts if the current time is outside the valid time range of the permission, but does not validate whether the
spend permission has been approved or revoked.

```solidity theme={null}
function getCurrentPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);
```
