Skip to content

Commit 32a888b

Browse files
add eoa guide
1 parent 06c4afc commit 32a888b

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

gator-sidebar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const sidebar = {
6666
items: [
6767
'guides/smart-accounts/signers/dynamic',
6868
'guides/smart-accounts/signers/embedded-wallets',
69+
'guides/smart-accounts/signers/eoa-wallets',
6970
'guides/smart-accounts/signers/privy',
7071
],
7172
},
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
description: Learn how to use Externally Owned Account (EOA) with MetaMask Smart Accounts.
3+
sidebar_label: EOA (e.g. MetaMask)
4+
keywords: [metamask, smart account, signer, metamask smart account]
5+
---
6+
7+
# Use Externally Owned Account (EOA) with MetaMask Smart Accounts
8+
9+
Externally Owned Account (EOA) are one of the most widely used wallet (e.g. MetaMask, Phantom, and more) whcih consists of public
10+
keypair where the private key is only known to the user. MetaMask Smart Accounts is a signer agnostic implementation that allows you
11+
to use EOA as a signer for MetaMask Smart Accounts.
12+
13+
:::info
14+
This guide is targeted towards React and React-based frameworks. For Vue, see [Wagmi docs](https://wagmi.sh/vue/getting-started).
15+
:::
16+
17+
## Prerequisites
18+
19+
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later
20+
- Install [Yarn](https://yarnpkg.com/),
21+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager
22+
23+
## Steps
24+
25+
### 1. Install dependencies
26+
27+
Install the [Smart Accounts Kit](https://www.npmjs.com/package/@metamask/smart-accounts-kit) and other dependencies in your project:
28+
29+
```bash npm2yarn
30+
npm install @metamask/smart-accounts-kit wagmi @tanstack/react-query viem
31+
```
32+
33+
### 2. Create the App provider
34+
35+
Once you've created the `AppProvider`, wrap it at the root of your application so
36+
that the rest of your application has access to the Wagmi's and TanStack's context.
37+
This will allow every component inside the provider to use the Wagmi hooks.
38+
39+
For the advance configuration, see [Wagmi's createConfig API reference](https://wagmi.sh/react/api/createConfig).
40+
41+
<Tabs>
42+
<TabItem value = "provider.ts">
43+
44+
```ts
45+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
46+
import { ReactNode } from "react";
47+
import { WagmiProvider } from 'wagmi'
48+
import { config } from "./config.ts";
49+
50+
const queryClient = new QueryClient();
51+
52+
export function AppProvider({ children }: { children: ReactNode }) {
53+
return (
54+
<WagmiProvider config={config}>
55+
<QueryClientProvider client={queryClient}>
56+
{children}
57+
</QueryClientProvider>
58+
</WagmiProvider>
59+
);
60+
}
61+
```
62+
63+
</TabItem>
64+
65+
<TabItem value = "config.ts">
66+
67+
```ts
68+
import { createConfig, http } from "wagmi";
69+
import { sepolia } from "viem/chains";
70+
71+
export const config = createConfig({
72+
chains: [sepolia],
73+
transports: {
74+
[sepolia.id]: http(),
75+
},
76+
});
77+
```
78+
79+
</TabItem>
80+
</Tabs>
81+
82+
### 3. Create a smart account
83+
84+
Once the user has connected their wallet, use the [Wallet Client](https://viem.sh/docs/clients/wallet) from Wagmi as the signer to create a
85+
MetaMask smart account.
86+
87+
```ts
88+
import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit";
89+
import { useAccount, usePublicClient, useWalletClient } from "wagmi";
90+
91+
const { address } = useAccount();
92+
const publicClient = usePublicClient();
93+
const { data: walletClient } = useWalletClient();
94+
95+
// Additional check to make sure the EOA wallet is connected
96+
// and values are available.
97+
if (!address || !walletClient || !publicClient ) {
98+
// Handle the error case
99+
}
100+
101+
const smartAccount = await toMetaMaskSmartAccount({
102+
client: publicClient,
103+
implementation: Implementation.Hybrid,
104+
deployParams: [address, [], [], []],
105+
deploySalt: "0x",
106+
signer: { walletClient },
107+
});
108+
```
109+
110+
## Next steps
111+
112+
- See how to use [MetaMask Embedded Wallets as a signer](./eoa-wallets.md) to make user onboarding journey easier.
113+
- See how to [send a user operations](../send-user-operation.md).
114+
- To sponsor gas for end users, see how to [send a gasless transaction](../send-gasless-transaction.md).

smart-accounts-kit/guides/smart-accounts/signers/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Checkout the following guides to learn how to configure different signers:
3535
title: "Dynamic",
3636
description: "Learn how to use Dynamic with MetaMask Smart Accounts.",
3737
},
38+
{
39+
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/eoa-wallets",
40+
title: "EOA (e.g. MetaMask)",
41+
description: "Learn how to use EOAs like MetaMAsk with MetaMask Smart Accounts.",
42+
},
3843
{
3944
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/privy",
4045
title: "Privy",

0 commit comments

Comments
 (0)