Skip to content

Patch Permissions guide and reference #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/base-account/improve-ux/spend-permissions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ After the user signs the permission, the `spender` can initiate transfers within

Read more about the Spend Permission Manager contract and supported chains on [GitHub](https://github.com/coinbase/spend-permissions).

<Callout type="info">
Spend Permissions for Base App Mini Apps are coming soon and will be supported in a future update.
</Callout>

## Usage

### Request a Spend Permission
Expand All @@ -31,6 +35,14 @@ You create an EIP-712 payload that describes the permission and ask the user to

```tsx
import { requestSpendPermission } from "@base-org/account/spend-permission";
import { createBaseAccountSDK } from "@base-org/account";
import { base } from "viem/chains";

const sdk = createBaseAccountSDK({
appName: 'Base Account SDK Demo',
appLogoUrl: 'https://base.org/logo.png',
appChainIds: [base.id],
});

const permission = await requestSpendPermission({
account: "0x...",
Expand All @@ -39,6 +51,7 @@ const permission = await requestSpendPermission({
chainId: 8453, // or any other supported chain
allowance: 1_000_000n,
periodInDays: 30,
provider: sdk.getProvider(),
});

console.log("Spend Permission:", permission);
Expand Down Expand Up @@ -177,13 +190,23 @@ import {
prepareRevokeCallData,
} from "@base-org/account/spend-permission";

import { createBaseAccountSDK } from "@base-org/account";
import { base } from "viem/chains";

const sdk = createBaseAccountSDK({
appName: 'Base Account SDK Demo',
appLogoUrl: 'https://base.org/logo.png',
appChainIds: [base.id],
});

const spender = "0xAppSpenderAddress";

// 1) Fetch available permissions
const permissions = await fetchPermissions({
account: "0xUserBaseAccountAddress",
chainId: 84532,
spender,
provider: sdk.getProvider(),
});

// ========================================
Expand Down Expand Up @@ -237,6 +260,7 @@ const newPermission = await requestSpendPermission({
chainId: 84532,
allowance: 1_000_000n,
periodInDays: 30,
provider: sdk.getProvider(),
});

// 3. prepare the calls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,62 @@ Defined in the [Base Account SDK](https://github.com/base/account-sdk)
Spender address you intend to use for spending.
</ParamField>

<ParamField body="provider" type="EIP1193Provider" required>
EIP-1193 compliant Ethereum provider instance. Get this from `sdk.getProvider()`.
</ParamField>

## Returns

<ResponseField name="permissions" type="SpendPermission[]">
Array of spend permissions matching the query.

<Expandable title="SpendPermission properties">
<ResponseField name="permissionHash" type="string">
Deterministic EIP-712 hash of the permission.
</ResponseField>

<ResponseField name="signature" type="string">
Signature for the EIP-712 payload.
</ResponseField>

<ResponseField name="chainId" type="number">
Target chain ID.
</ResponseField>

<ResponseField name="permission" type="object">
Underlying permission fields.

<Expandable title="permission fields">
<ResponseField name="account" type="address" />
<ResponseField name="spender" type="address" />
<ResponseField name="token" type="address" />
<ResponseField name="allowance" type="bigint" />
<ResponseField name="period" type="number">Duration in seconds.</ResponseField>
<ResponseField name="start" type="number">Unix timestamp (seconds).</ResponseField>
<ResponseField name="end" type="number">Unix timestamp (seconds).</ResponseField>
<ResponseField name="salt" type="string" />
<ResponseField name="extraData" type="string" />
</Expandable>
</ResponseField>
</Expandable>
</ResponseField>

<RequestExample>
```typescript Fetch permissions
import { fetchPermissions } from "@base-org/account/spend-permission";
import { createBaseAccountSDK } from "@base-org/account";

const sdk = createBaseAccountSDK({
appName: 'My App',
appLogoUrl: 'https://example.com/logo.png',
appChainIds: [84532],
});

const permissions = await fetchPermissions({
account: "0xUserBaseAccountAddress",
chainId: 84532,
spender: "0xAppSpenderAddress",
provider: sdk.getProvider(),
});
```
</RequestExample>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,37 @@ Defined in the [Base Account SDK](https://github.com/base/account-sdk)
## Parameters

<ParamField body="permission" type="SpendPermission" required>
Signed permission to evaluate.
Signed permission to evaluate. This should be a SpendPermission object returned from [`requestSpendPermission`](/base-account/reference/spend-permission-utilities/requestSpendPermission) or fetched via [`fetchPermissions`](/base-account/reference/spend-permission-utilities/fetchPermissions).

<Expandable title="SpendPermission properties">
<ParamField body="permissionHash" type="string">
Deterministic EIP-712 hash of the permission.
</ParamField>

<ParamField body="signature" type="string">
Signature for the EIP-712 payload.
</ParamField>

<ParamField body="chainId" type="number">
Target chain ID.
</ParamField>

<ParamField body="permission" type="object">
Underlying permission fields.

<Expandable title="permission fields">
<ParamField body="account" type="address" />
<ParamField body="spender" type="address" />
<ParamField body="token" type="address" />
<ParamField body="allowance" type="bigint" />
<ParamField body="period" type="number">Duration in seconds.</ParamField>
<ParamField body="start" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="end" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="salt" type="string" />
<ParamField body="extraData" type="string" />
</Expandable>
</ParamField>
</Expandable>
</ParamField>

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,37 @@ Defined in the [Base Account SDK](https://github.com/base/account-sdk)
## Parameters

<ParamField body="permission" type="SpendPermission" required>
The permission to revoke.
The spend permission to revoke. This should be a SpendPermission object returned from [`requestSpendPermission`](/base-account/reference/spend-permission-utilities/requestSpendPermission) or fetched via [`fetchPermissions`](/base-account/reference/spend-permission-utilities/fetchPermissions).

<Expandable title="SpendPermission properties">
<ParamField body="permissionHash" type="string">
Deterministic EIP-712 hash of the permission.
</ParamField>

<ParamField body="signature" type="string">
Signature for the EIP-712 payload.
</ParamField>

<ParamField body="chainId" type="number">
Target chain ID.
</ParamField>

<ParamField body="permission" type="object">
Underlying permission fields.

<Expandable title="permission fields">
<ParamField body="account" type="address" />
<ParamField body="spender" type="address" />
<ParamField body="token" type="address" />
<ParamField body="allowance" type="bigint" />
<ParamField body="period" type="number">Duration in seconds.</ParamField>
<ParamField body="start" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="end" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="salt" type="string" />
<ParamField body="extraData" type="string" />
</Expandable>
</ParamField>
</Expandable>
</ParamField>

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,37 @@ Defined in the [Base Account SDK](https://github.com/base/account-sdk)
## Parameters

<ParamField body="permission" type="SpendPermission" required>
Signed permission returned from `requestSpendPermission` or fetched via
`fetchPermissions`.
Signed permission returned from [`requestSpendPermission`](/base-account/reference/spend-permission-utilities/requestSpendPermission) or fetched via [`fetchPermissions`](/base-account/reference/spend-permission-utilities/fetchPermissions).

<Expandable title="SpendPermission properties">
<ParamField body="permissionHash" type="string">
Deterministic EIP-712 hash of the permission.
</ParamField>

<ParamField body="signature" type="string">
Signature for the EIP-712 payload.
</ParamField>

<ParamField body="chainId" type="number">
Target chain ID.
</ParamField>

<ParamField body="permission" type="object">
Underlying permission fields.

<Expandable title="permission fields">
<ParamField body="account" type="address" />
<ParamField body="spender" type="address" />
<ParamField body="token" type="address" />
<ParamField body="allowance" type="bigint" />
<ParamField body="period" type="number">Duration in seconds.</ParamField>
<ParamField body="start" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="end" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="salt" type="string" />
<ParamField body="extraData" type="string" />
</Expandable>
</ParamField>
</Expandable>
</ParamField>

<ParamField body="amount" type="bigint">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,37 @@ Defined in the [Base Account SDK](https://github.com/base/account-sdk)
## Parameters

<ParamField body="permission" type="SpendPermission" required>
The permission to revoke.
The spend permission to revoke. This should be a SpendPermission object returned from [`requestSpendPermission`](/base-account/reference/spend-permission-utilities/requestSpendPermission) or fetched via [`fetchPermissions`](/base-account/reference/spend-permission-utilities/fetchPermissions).

<Expandable title="SpendPermission properties">
<ParamField body="permissionHash" type="string">
Deterministic EIP-712 hash of the permission.
</ParamField>

<ParamField body="signature" type="string">
Signature for the EIP-712 payload.
</ParamField>

<ParamField body="chainId" type="number">
Target chain ID.
</ParamField>

<ParamField body="permission" type="object">
Underlying permission fields.

<Expandable title="permission fields">
<ParamField body="account" type="address" />
<ParamField body="spender" type="address" />
<ParamField body="token" type="address" />
<ParamField body="allowance" type="bigint" />
<ParamField body="period" type="number">Duration in seconds.</ParamField>
<ParamField body="start" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="end" type="number">Unix timestamp (seconds).</ParamField>
<ParamField body="salt" type="string" />
<ParamField body="extraData" type="string" />
</Expandable>
</ParamField>
</Expandable>
</ParamField>

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Defined in the [Base Account SDK](https://github.com/base/account-sdk)
Arbitrary data to attach to the permission. Hex string. Defaults to `0x`.
</ParamField>

<ParamField body="provider" type="EIP1193Provider" required>
EIP-1193 compliant Ethereum provider instance. Get this from `sdk.getProvider()`.
</ParamField>

## Returns

<ResponseField name="permission" type="SpendPermission">
Expand Down Expand Up @@ -93,6 +97,13 @@ Underlying permission fields.
<RequestExample>
```typescript Create and sign a spend permission
import { requestSpendPermission } from "@base-org/account/spend-permission";
import { createBaseAccountSDK } from "@base-org/account";

const sdk = createBaseAccountSDK({
appName: 'My App',
appLogoUrl: 'https://example.com/logo.png',
appChainIds: [84532],
});

const permission = await requestSpendPermission({
account: "0xUserBaseAccountAddress",
Expand All @@ -101,6 +112,7 @@ const permission = await requestSpendPermission({
chainId: 84532,
allowance: 1_000_000n,
periodInDays: 30,
provider: sdk.getProvider(),
});

console.log("Spend Permission:", permission);
Expand Down