|
| 1 | +--- |
| 2 | +description: ERC-7715 permissions reference. |
| 3 | +sidebar_label: Permissions |
| 4 | +keywords: [ERC-7715, permissions, ERC-20 token, native token, reference] |
| 5 | +--- |
| 6 | + |
| 7 | +# ERC-7715 permissions |
| 8 | + |
| 9 | +When [executing on a MetaMask user's behalf](../../guides/erc7715/execute-on-metamask-users-behalf.md), you can request the following permission types for ERC-20 token and native token transfers. |
| 10 | +Learn [how to use ERC-7715 permissions](../../guides/erc7715/use-permissions/erc20-token.md). |
| 11 | + |
| 12 | +## ERC-20 token permissions |
| 13 | + |
| 14 | +### ERC-20 periodic permission |
| 15 | + |
| 16 | +Ensures a per-period limit for ERC-20 token transfers. |
| 17 | +At the start of each new period, the allowance resets. |
| 18 | + |
| 19 | +#### Parameters |
| 20 | + |
| 21 | +| Name | Type | Required | Description | |
| 22 | +| ---------------- | --------- | -------- | ---------------------------------------------------------------- | |
| 23 | +| `tokenAddress` | `Address` | Yes | The ERC-20 token contract address as a hex string. | |
| 24 | +| `periodAmount` | `bigint` | Yes | The maximum amount of tokens that can be transferred per period. | |
| 25 | +| `periodDuration` | `number` | Yes | The duration of each period in seconds. | |
| 26 | +| `justification` | `string` | No | A description of the permission to display to the user. | |
| 27 | + |
| 28 | +#### Example |
| 29 | + |
| 30 | +```typescript |
| 31 | +import { sepolia as chain } from "viem/chains"; |
| 32 | +import { parseUnits } from "viem"; |
| 33 | +import { walletClient } from "./client.ts" |
| 34 | + |
| 35 | +const currentTime = Math.floor(Date.now() / 1000); |
| 36 | +const expiry = currentTime + 604800; |
| 37 | + |
| 38 | +const grantedPermissions = await walletClient.requestExecutionPermissions([{ |
| 39 | + chainId: chain.id, |
| 40 | + expiry, |
| 41 | + signer: { |
| 42 | + type: "account", |
| 43 | + data: { |
| 44 | + address: sessionAccountAddress, |
| 45 | + }, |
| 46 | + }, |
| 47 | + permission: { |
| 48 | + type: "erc20-token-periodic", |
| 49 | + data: { |
| 50 | + tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", |
| 51 | + periodAmount: parseUnits("10", 6), |
| 52 | + periodDuration: 86400, |
| 53 | + justification?: "Permission to transfer 1 USDC every day", |
| 54 | + }, |
| 55 | + }, |
| 56 | +}]); |
| 57 | +``` |
| 58 | + |
| 59 | +### ERC-20 stream permission |
| 60 | + |
| 61 | +Ensures a linear streaming transfer limit for ERC-20 tokens. |
| 62 | +Token transfers are blocked until the defined start timestamp. |
| 63 | +At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount. |
| 64 | + |
| 65 | +#### Parameters |
| 66 | + |
| 67 | +| Name | Type | Required | Description | |
| 68 | +| ----------------- | --------- | -------- | --------------------------------------------------------- | |
| 69 | +| `tokenAddress` | `Address` | Yes | The ERC-20 token contract address. | |
| 70 | +| `initialAmount` | `bigint` | Yes | The initial amount that can be transferred at start time. | |
| 71 | +| `maxAmount` | `bigint` | Yes | The maximum total amount that can be unlocked. | |
| 72 | +| `amountPerSecond` | `bigint` | Yes | The rate at which tokens accrue per second. | |
| 73 | +| `duration` | `number` | Yes | The duration of the stream in seconds. | |
| 74 | +| `startTime` | `number` | Yes | The start timestamp in seconds. | |
| 75 | +| `justification` | `string` | No | A description of the permission to display to the user. | |
| 76 | + |
| 77 | +#### Example |
| 78 | + |
| 79 | +```typescript |
| 80 | +import { sepolia as chain } from "viem/chains"; |
| 81 | +import { parseUnits } from "viem"; |
| 82 | +import { walletClient } from "./client.ts" |
| 83 | + |
| 84 | +const currentTime = Math.floor(Date.now() / 1000); |
| 85 | +const expiry = currentTime + 604800; |
| 86 | + |
| 87 | +const grantedPermissions = await walletClient.requestExecutionPermissions([{ |
| 88 | + chainId: chain.id, |
| 89 | + expiry, |
| 90 | + signer: { |
| 91 | + type: "account", |
| 92 | + data: { |
| 93 | + address: sessionAccountAddress, |
| 94 | + }, |
| 95 | + }, |
| 96 | + permission: { |
| 97 | + type: "erc20-token-stream", |
| 98 | + data: { |
| 99 | + tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", |
| 100 | + amountPerSecond: parseUnits("0.1", 6), |
| 101 | + initialAmount: parseUnits("1", 6), |
| 102 | + maxAmount: parseUnits("2", 6), |
| 103 | + duration: 3600, |
| 104 | + startTime: currentTime, |
| 105 | + justification: "Permission to use 0.1 USDC per second", |
| 106 | + }, |
| 107 | + }, |
| 108 | +}]); |
| 109 | +``` |
| 110 | + |
| 111 | +## Native token permissions |
| 112 | + |
| 113 | +### Native token periodic permission |
| 114 | + |
| 115 | +Ensures a per-period limit for native token transfers. |
| 116 | +At the start of each new period, the allowance resets. |
| 117 | + |
| 118 | +#### Parameters |
| 119 | + |
| 120 | +| Name | Type | Required | Description | |
| 121 | +| ---------------- | --------- | -------- | ---------------------------------------------------------------- | |
| 122 | +| `periodAmount` | `bigint` | Yes | The maximum amount of tokens that can be transferred per period. | |
| 123 | +| `periodDuration` | `number` | Yes | The duration of each period in seconds. | |
| 124 | +| `startTime` | `number` | Yes | The start timestamp in seconds. | |
| 125 | +| `justification` | `string` | No | A description of the permission to display to the user. | |
| 126 | + |
| 127 | +#### Example |
| 128 | + |
| 129 | +```typescript |
| 130 | +import { sepolia as chain } from "viem/chains"; |
| 131 | +import { parseEther } from "viem"; |
| 132 | +import { walletClient } from "./client.ts" |
| 133 | + |
| 134 | +const currentTime = Math.floor(Date.now() / 1000); |
| 135 | +const expiry = currentTime + 604800; |
| 136 | + |
| 137 | +const grantedPermissions = await walletClient.requestExecutionPermissions([{ |
| 138 | + chainId: chain.id, |
| 139 | + expiry, |
| 140 | + signer: { |
| 141 | + type: "account", |
| 142 | + data: { |
| 143 | + address: sessionAccountAddress, |
| 144 | + }, |
| 145 | + }, |
| 146 | + permission: { |
| 147 | + type: "native-token-periodic", |
| 148 | + data: { |
| 149 | + periodAmount: parseEther("0.001"), |
| 150 | + periodDuration: 86400, |
| 151 | + startTime: currentTime, |
| 152 | + justification: "Permission to use 0.001 ETH every day", |
| 153 | + }, |
| 154 | + }, |
| 155 | +}]); |
| 156 | +``` |
| 157 | + |
| 158 | +### Native token stream permission |
| 159 | + |
| 160 | +Ensures a linear streaming transfer limit for native tokens. |
| 161 | +Token transfers are blocked until the defined start timestamp. |
| 162 | +At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount. |
| 163 | + |
| 164 | +#### Parameters |
| 165 | + |
| 166 | +| Name | Type | Required | Description | |
| 167 | +| ----------------- | --------- | -------- | --------------------------------------------------------- | |
| 168 | +| `initialAmount` | `bigint` | Yes | The initial amount that can be transferred at start time. | |
| 169 | +| `maxAmount` | `bigint` | Yes | The maximum total amount that can be unlocked. | |
| 170 | +| `amountPerSecond` | `bigint` | Yes | The rate at which tokens accrue per second. | |
| 171 | +| `duration` | `number` | Yes | The duration of the stream in seconds. | |
| 172 | +| `startTime` | `number` | Yes | The start timestamp in seconds. | |
| 173 | +| `justification` | `string` | No | A description of the permission to display to the user. | |
| 174 | + |
| 175 | +#### Example |
| 176 | + |
| 177 | +```typescript |
| 178 | +import { sepolia as chain } from "viem/chains"; |
| 179 | +import { parseEther } from "viem"; |
| 180 | +import { walletClient } from "./client.ts" |
| 181 | + |
| 182 | +const currentTime = Math.floor(Date.now() / 1000); |
| 183 | +const expiry = currentTime + 604800; |
| 184 | + |
| 185 | +const grantedPermissions = await walletClient.requestExecutionPermissions([{ |
| 186 | + chainId: chain.id, |
| 187 | + expiry, |
| 188 | + signer: { |
| 189 | + type: "account", |
| 190 | + data: { |
| 191 | + address: sessionAccountAddress, |
| 192 | + }, |
| 193 | + }, |
| 194 | + permission: { |
| 195 | + type: "native-token-stream", |
| 196 | + data: { |
| 197 | + amountPerSecond: parseEther("0.0001"), |
| 198 | + initialAmount: parseEther("0.1"), |
| 199 | + maxAmount: parseEther("1"), |
| 200 | + duration: 3600, |
| 201 | + startTime: currentTime, |
| 202 | + justification: "Permission to use 0.0001 ETH per second", |
| 203 | + }, |
| 204 | + }, |
| 205 | +}]); |
| 206 | +``` |
0 commit comments