|
| 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 | +| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. | |
| 27 | +| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. | |
| 28 | + |
| 29 | +#### Example |
| 30 | + |
| 31 | +```typescript |
| 32 | +import { parseUnits } from "viem"; |
| 33 | + |
| 34 | +const currentTime = Math.floor(Date.now() / 1000); |
| 35 | +const expiry = currentTime + 604800; |
| 36 | + |
| 37 | +const permission = { |
| 38 | + type: "erc20-token-periodic", |
| 39 | + data: { |
| 40 | + tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", |
| 41 | + periodAmount: parseUnits("10", 6), |
| 42 | + periodDuration: 86400, |
| 43 | + justification?: "Permission to transfer 1 USDC every day", |
| 44 | + }, |
| 45 | +}; |
| 46 | +``` |
| 47 | + |
| 48 | +### ERC-20 stream permission |
| 49 | + |
| 50 | +Ensures a linear streaming transfer limit for ERC-20 tokens. |
| 51 | +Token transfers are blocked until the defined start timestamp. |
| 52 | +At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount. |
| 53 | + |
| 54 | +#### Parameters |
| 55 | + |
| 56 | +| Name | Type | Required | Description | |
| 57 | +| ----------------- | --------- | -------- | ----------------------------------------------------------------------------- | |
| 58 | +| `tokenAddress` | `Address` | Yes | The ERC-20 token contract address. | |
| 59 | +| `initialAmount` | `bigint` | No | The initial amount that can be transferred at start time. The default is `0`. | |
| 60 | +| `maxAmount` | `bigint` | No | The maximum total amount that can be unlocked. The default is no limit. | |
| 61 | +| `amountPerSecond` | `bigint` | Yes | The rate at which tokens accrue per second. | |
| 62 | +| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. | |
| 63 | +| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. | |
| 64 | + |
| 65 | +#### Example |
| 66 | + |
| 67 | +```typescript |
| 68 | +import { parseUnits } from "viem"; |
| 69 | + |
| 70 | +const currentTime = Math.floor(Date.now() / 1000); |
| 71 | +const expiry = currentTime + 604800; |
| 72 | + |
| 73 | +const permission = { |
| 74 | + type: "erc20-token-stream", |
| 75 | + data: { |
| 76 | + tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", |
| 77 | + amountPerSecond: parseUnits("0.1", 6), |
| 78 | + initialAmount: parseUnits("1", 6), |
| 79 | + maxAmount: parseUnits("2", 6), |
| 80 | + startTime: currentTime, |
| 81 | + justification: "Permission to use 0.1 USDC per second", |
| 82 | + }, |
| 83 | +}; |
| 84 | +``` |
| 85 | + |
| 86 | +## Native token permissions |
| 87 | + |
| 88 | +### Native token periodic permission |
| 89 | + |
| 90 | +Ensures a per-period limit for native token transfers. |
| 91 | +At the start of each new period, the allowance resets. |
| 92 | + |
| 93 | +#### Parameters |
| 94 | + |
| 95 | +| Name | Type | Required | Description | |
| 96 | +| ---------------- | --------- | -------- | ---------------------------------------------------------------------- | |
| 97 | +| `periodAmount` | `bigint` | Yes | The maximum amount of tokens that can be transferred per period. | |
| 98 | +| `periodDuration` | `number` | Yes | The duration of each period in seconds. | |
| 99 | +| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. | |
| 100 | +| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. | |
| 101 | + |
| 102 | +#### Example |
| 103 | + |
| 104 | +```typescript |
| 105 | +import { parseEther } from "viem"; |
| 106 | + |
| 107 | +const currentTime = Math.floor(Date.now() / 1000); |
| 108 | +const expiry = currentTime + 604800; |
| 109 | + |
| 110 | +const permission = { |
| 111 | + type: "native-token-periodic", |
| 112 | + data: { |
| 113 | + periodAmount: parseEther("0.001"), |
| 114 | + periodDuration: 86400, |
| 115 | + startTime: currentTime, |
| 116 | + justification: "Permission to use 0.001 ETH every day", |
| 117 | + }, |
| 118 | +}; |
| 119 | +``` |
| 120 | + |
| 121 | +### Native token stream permission |
| 122 | + |
| 123 | +Ensures a linear streaming transfer limit for native tokens. |
| 124 | +Token transfers are blocked until the defined start timestamp. |
| 125 | +At the start, a specified initial amount is released, after which tokens accrue linearly at the configured rate, up to the maximum allowed amount. |
| 126 | + |
| 127 | +#### Parameters |
| 128 | + |
| 129 | +| Name | Type | Required | Description | |
| 130 | +| ----------------- | --------- | -------- | ----------------------------------------------------------------------------- | |
| 131 | +| `initialAmount` | `bigint` | No | The initial amount that can be transferred at start time. The default is `0`. | |
| 132 | +| `maxAmount` | `bigint` | No | The maximum total amount that can be unlocked. The default is no limit. | |
| 133 | +| `amountPerSecond` | `bigint` | Yes | The rate at which tokens accrue per second. | |
| 134 | +| `startTime` | `number` | No | The start timestamp in seconds. The default is the current time. | |
| 135 | +| `justification` | `string` | No | A human-readable explanation of why the permission is being requested. | |
| 136 | + |
| 137 | +#### Example |
| 138 | + |
| 139 | +```typescript |
| 140 | +import { sepolia as chain } from "viem/chains"; |
| 141 | +import { parseEther } from "viem"; |
| 142 | +import { walletClient } from "./client.ts" |
| 143 | + |
| 144 | +const currentTime = Math.floor(Date.now() / 1000); |
| 145 | +const expiry = currentTime + 604800; |
| 146 | + |
| 147 | +const permission = { |
| 148 | + type: "native-token-stream", |
| 149 | + data: { |
| 150 | + amountPerSecond: parseEther("0.0001"), |
| 151 | + initialAmount: parseEther("0.1"), |
| 152 | + maxAmount: parseEther("1"), |
| 153 | + startTime: currentTime, |
| 154 | + justification: "Permission to use 0.0001 ETH per second", |
| 155 | + }, |
| 156 | +}; |
| 157 | +``` |
0 commit comments