Skip to content

Commit

Permalink
feat(experimental): ERC-7115 (#2317)
Browse files Browse the repository at this point in the history
* feat: add experimental erc7115

* chore: changeset
  • Loading branch information
jxom committed May 27, 2024
1 parent d30b694 commit 3135a0c
Show file tree
Hide file tree
Showing 11 changed files with 912 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-hairs-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": minor
---

**Experimental:** Added ERC-7115 extension.
171 changes: 171 additions & 0 deletions site/pages/experimental/erc7115/issuePermissions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
description: Request permissions from a wallet to perform actions on behalf of a user.
---

# issuePermissions

Request permissions from a wallet to perform actions on behalf of a user.

[Read more.](https://eips.ethereum.org/EIPS/eip-7115)

:::warning[Warning]
This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.
:::

## Usage

:::code-group

```ts twoslash [example.ts]
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const result = await walletClient.issuePermissions({ // [!code focus:99]
account,
expiry: 1716846083638,
permissions: [
{
type: 'native-token-limit',
data: {
amount: parseEther('0.5'),
},
required: true,
},
],
})
```

```ts twoslash [config.ts] filename="config.ts"
import 'viem/window'
// ---cut---
import { createWalletClient, custom } from 'viem'
import { mainnet } from 'viem/chains'
import { walletActionsErc7115 } from 'viem/experimental'

export const walletClient = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum!),
}).extend(walletActionsErc7115())

export const [account] = await walletClient.getAddresses()
```

:::

## Returns

`IssuePermissionsReturnType`

Response from the wallet after issuing permissions.

## Parameters

### account

- **Type:** `Account | Address | undefined`

The Account to scope the permissions to.

```ts twoslash
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const result = await walletClient.issuePermissions({
account, // [!code focus]
expiry: 1716846083638,
permissions: [
{
type: 'native-token-limit',
data: {
amount: parseEther('0.5'),
},
required: true,
},
],
})
```

### expiry

- **Type:** `number`

The timestamp (in seconds) when the permissions will expire.

```ts twoslash
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const result = await walletClient.issuePermissions({
account,
expiry: 1716846083638, // [!code focus]
permissions: [
{
type: 'native-token-limit',
data: {
amount: parseEther('0.5'),
},
required: true,
},
],
})
```

### permissions

- **Type:** `Permission[]`

Set of permissions to grant to the user.

```ts twoslash
// @noErrors
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const result = await walletClient.issuePermissions({
account,
expiry: 1716846083638,
permissions: [ // [!code focus:99]
{
type: 'native-token-limit',
data: {
amount: parseEther('0.5'),
},
required: true,
},
{
type: '
// ^|
}
],
})
```

### signer

- **Type:** `Signer | undefined`

Custom signer type to scope the permissions to.

```ts twoslash
import { parseEther } from 'viem'
import { account, walletClient } from './config'

const result = await walletClient.issuePermissions({
expiry: 1716846083638,
permissions: [
{
type: 'native-token-limit',
data: {
amount: parseEther('0.5'),
},
required: true,
},
],
signer: { // [!code focus]
type: 'key', // [!code focus]
data: { // [!code focus]
id: '...' // [!code focus]
} // [!code focus]
} // [!code focus]
})
```
14 changes: 14 additions & 0 deletions site/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,20 @@ export const sidebar = {
},
],
},
{
text: 'ERC-7115',
items: [
{
text: 'Actions',
items: [
{
text: 'issuePermissions',
link: '/experimental/erc7115/issuePermissions',
},
],
},
],
},
],
},
'/op-stack': {
Expand Down
Loading

0 comments on commit 3135a0c

Please sign in to comment.