Skip to content

Commit fee80a9

Browse files
authored
feat: EIP-7702 (#2570)
* wip: checkpoint * chore: format * wip: checkpoint * wip: checkpoint * chore: format * wip: checkpoint * wip: checkpoint * wip: format * wip: checkpoint * wip: checkpoint * wip: format * wip: tweaks * wip: docs * wip: checkpoint * wip: format * chore: tweaks * wip: checkpoint * wip: format * wip: checkpoint * wip: checkpoint * wip: format * wip: docs * wip: checkpoint * wip: format * wip: up * wip: tweak * wip: checkpoint * wip: tweaks * chore: tweak * wip: tweak contract * format * wip: transaction types * wip: estimateGas * wip: format * wip: tests * wip: docs * wip: docs * docs: wip * wip: docs * wip: docs * chore: changeset * types * test * test * format
1 parent 8570315 commit fee80a9

File tree

97 files changed

+5063
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+5063
-315
lines changed

.changeset/metal-points-leave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": minor
3+
---
4+
5+
**Experimental:** Added EIP-7702 Extension. [See Docs](https://viem.sh/experimental/eip7702)

.vscode/settings.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
"typescript.updateImportsOnFileMove.enabled": "always",
66
"typescript.tsdk": "node_modules/typescript/lib",
77
"typescript.enablePromptUseWorkspaceTsdk": true,
8-
"javascript.preferences.autoImportFileExcludePatterns": [
9-
"**/node_modules/**",
10-
"**/_types/**"
11-
],
12-
"typescript.preferences.autoImportFileExcludePatterns": [
13-
"**/node_modules/**",
14-
"**/_types/**"
15-
],
8+
"javascript.preferences.autoImportFileExcludePatterns": ["**/_types/**"],
9+
"typescript.preferences.autoImportFileExcludePatterns": ["**/_types/**"],
1610
"[json]": {
1711
"editor.defaultFormatter": "biomejs.biome"
1812
},
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.13;
3+
4+
contract BatchCallInvoker {
5+
struct Call {
6+
bytes data;
7+
address to;
8+
uint256 value;
9+
}
10+
11+
event CallEmitted(address indexed to, uint256 value, bytes data);
12+
13+
function execute(Call[] calldata calls) external payable {
14+
for (uint256 i = 0; i < calls.length; i++) {
15+
Call memory call = calls[i];
16+
17+
(bool success, ) = call.to.call{value: call.value}(call.data);
18+
require(success, "call reverted");
19+
20+
emit CallEmitted(call.to, call.value, call.data);
21+
}
22+
}
23+
}

contracts/src/test/Event.sol

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.13;
3+
4+
contract Event {
5+
event MessageEmitted(address indexed to, uint256 value, bytes data);
6+
7+
function execute() external payable {
8+
emit MessageEmitted(msg.sender, msg.value, msg.data);
9+
}
10+
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"ethers": "^6.0.2",
6565
"glob": "^10.4.1",
6666
"knip": "^5.17.4",
67-
"prool": "^0.0.15",
67+
"prool": "^0.0.16",
6868
"publint": "^0.2.8",
6969
"sherif": "^0.8.4",
7070
"simple-git-hooks": "^2.8.1",
@@ -187,7 +187,7 @@
187187
{
188188
"name": "import { getEnsAvatar } from 'viem/ens'",
189189
"path": "./src/_esm/ens/index.js",
190-
"limit": "22.7 kB",
190+
"limit": "23 kB",
191191
"import": "{ getEnsAvatar }"
192192
},
193193
{

pnpm-lock.yaml

+33-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/pages/account-abstraction/guides/sending-user-operations.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ Next, we will need to set up a Bundler Client. A Bundler is required to submit U
7878

7979
```ts twoslash
8080
import { createPublicClient, http } from 'viem'
81-
import { createBundlerClient } from 'viem/account-abstraction' // [!code focus]
81+
import { createBundlerClient } from 'viem/account-abstraction' // [!code ++] // [!code focus]
8282
import { mainnet } from 'viem/chains'
8383

8484
const client = createPublicClient({
8585
chain: mainnet,
8686
transport: http(),
8787
})
8888

89-
const bundlerClient = createBundlerClient({ // [!code focus]
90-
client, // [!code focus]
91-
transport: http('https://public.pimlico.io/v2/1/rpc'), // [!code focus]
92-
}) // [!code focus]
89+
const bundlerClient = createBundlerClient({ // [!code ++] // [!code focus]
90+
client, // [!code ++] // [!code focus]
91+
transport: http('https://public.pimlico.io/v2/1/rpc'), // [!code ++] // [!code focus]
92+
}) // [!code ++] // [!code focus]
9393
```
9494

9595
:::info
@@ -107,7 +107,7 @@ We will also need to set up an Owner for the Smart Account which will be used to
107107
import { createPublicClient, http } from 'viem'
108108
import { createBundlerClient } from 'viem/account-abstraction'
109109
import { mainnet } from 'viem/chains'
110-
import { privateKeyToAccount } from 'viem/accounts' // [!code focus]
110+
import { privateKeyToAccount } from 'viem/accounts' // [!code ++] // [!code focus]
111111
112112
const client = createPublicClient({
113113
chain: mainnet,
@@ -119,7 +119,7 @@ const bundlerClient = createBundlerClient({
119119
transport: http('https://public.pimlico.io/v2/1/rpc'),
120120
})
121121

122-
const owner = privateKeyToAccount('0x...') // [!code focus]
122+
const owner = privateKeyToAccount('0x...') // [!code ++] // [!code focus]
123123
```
124124

125125
[See `privateKeyToAccount` Docs](/docs/accounts/local/privateKeyToAccount)
@@ -131,10 +131,10 @@ Next, we will instantiate a Smart Account. For this example, we will use [`toCoi
131131
```ts twoslash
132132
// @noErrors
133133
import { createPublicClient, http } from 'viem'
134-
import { // [!code focus]
135-
createBundlerClient, // [!code focus]
136-
toCoinbaseSmartAccount // [!code focus]
137-
} from 'viem/account-abstraction' // [!code focus]
134+
import { // [!code ++] // [!code focus]
135+
createBundlerClient, // [!code ++] // [!code focus]
136+
toCoinbaseSmartAccount // [!code ++] // [!code focus]
137+
} from 'viem/account-abstraction' // [!code ++] // [!code focus]
138138
import { mainnet } from 'viem/chains'
139139
import { privateKeyToAccount } from 'viem/accounts'
140140

@@ -150,10 +150,10 @@ const bundlerClient = createBundlerClient({
150150

151151
const owner = privateKeyToAccount('0x...')
152152

153-
const account = await toCoinbaseSmartAccount({ // [!code focus]
154-
client, // [!code focus]
155-
owners: [owner] // [!code focus]
156-
}) // [!code focus]
153+
const account = await toCoinbaseSmartAccount({ // [!code ++] // [!code focus]
154+
client, // [!code ++] // [!code focus]
155+
owners: [owner] // [!code ++] // [!code focus]
156+
}) // [!code ++] // [!code focus]
157157
```
158158

159159
:::tip
@@ -192,15 +192,15 @@ const account = await toCoinbaseSmartAccount({
192192
owners: [owner]
193193
})
194194

195-
const hash = await bundlerClient.sendUserOperation({ // [!code focus]
196-
account, // [!code focus]
197-
calls: [{ // [!code focus]
198-
to: '0xcb98643b8786950F0461f3B0edf99D88F274574D', // [!code focus]
199-
value: parseEther('0.001') // [!code focus]
200-
}] // [!code focus]
201-
}) // [!code focus]
195+
const hash = await bundlerClient.sendUserOperation({ // [!code ++] // [!code focus]
196+
account, // [!code ++] // [!code focus]
197+
calls: [{ // [!code ++] // [!code focus]
198+
to: '0xcb98643b8786950F0461f3B0edf99D88F274574D', // [!code ++] // [!code focus]
199+
value: parseEther('0.001') // [!code ++] // [!code focus]
200+
}] // [!code ++] // [!code focus]
201+
}) // [!code ++] // [!code focus]
202202

203-
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash }) // [!code focus]
203+
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash }) // [!code ++] // [!code focus]
204204
```
205205

206206
:::tip

site/pages/docs/accounts/local/signTransaction.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,29 @@ const signature = await account.signTransaction({
8282
storageKeys: ['0x1'],
8383
},
8484
],
85-
type: 'eip1559'
85+
chainId: 1,
86+
})
87+
```
88+
89+
### authorizationList (optional)
90+
91+
- **Type:** `AuthorizationList`
92+
93+
Signed EIP-7702 Authorization list.
94+
95+
```ts twoslash
96+
import { privateKeyToAccount } from 'viem/accounts'
97+
const account = privateKeyToAccount('0x...')
98+
// ---cut---
99+
const authorization = await account.experimental_signAuthorization({
100+
address: '0x...',
101+
chainId: 1,
102+
nonce: 1,
103+
})
104+
105+
const signature = await account.signTransaction({
106+
authorizationList: [authorization], // [!code focus]
107+
chainId: 1,
86108
})
87109
```
88110

0 commit comments

Comments
 (0)