-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimental): ERC-7115 (#2317)
* feat: add experimental erc7115 * chore: changeset
- Loading branch information
Showing
11 changed files
with
912 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"viem": minor | ||
--- | ||
|
||
**Experimental:** Added ERC-7115 extension. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.