-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Smart Accounts Kit] Add guide for EOA as a signer #2575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AyushBherwani1998
wants to merge
3
commits into
main
Choose a base branch
from
feat/eoa-guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
114 changes: 114 additions & 0 deletions
114
smart-accounts-kit/guides/smart-accounts/signers/eoa-wallets.md
This file contains hidden or 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,114 @@ | ||
| --- | ||
| description: Learn how to use Externally Owned Account (EOA) with MetaMask Smart Accounts. | ||
| sidebar_label: EOA (e.g. MetaMask) | ||
| keywords: [metamask, smart account, signer, metamask smart account] | ||
| --- | ||
|
|
||
| # Use Externally Owned Account (EOA) with MetaMask Smart Accounts | ||
|
|
||
| Externally Owned Account (EOA) are one of the most widely used wallet (e.g. MetaMask, Phantom, and more) whcih consists of public | ||
| keypair where the private key is only known to the user. MetaMask Smart Accounts is a signer agnostic implementation that allows you | ||
| to use EOA as a signer for MetaMask Smart Accounts. | ||
AyushBherwani1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| :::info | ||
| This guide is targeted towards React and React-based frameworks. For Vue, see [Wagmi docs](https://wagmi.sh/vue/getting-started). | ||
AyushBherwani1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ::: | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later | ||
| - Install [Yarn](https://yarnpkg.com/), | ||
| [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager | ||
|
|
||
| ## Steps | ||
|
|
||
| ### 1. Install dependencies | ||
|
|
||
| Install the [Smart Accounts Kit](https://www.npmjs.com/package/@metamask/smart-accounts-kit) and other dependencies in your project: | ||
|
|
||
| ```bash npm2yarn | ||
| npm install @metamask/smart-accounts-kit wagmi @tanstack/react-query viem | ||
| ``` | ||
|
|
||
| ### 2. Create the App provider | ||
|
|
||
| Once you've created the `AppProvider`, wrap it at the root of your application so | ||
| that the rest of your application has access to the Wagmi's and TanStack's context. | ||
| This will allow every component inside the provider to use the Wagmi hooks. | ||
|
|
||
| For the advance configuration, see [Wagmi's createConfig API reference](https://wagmi.sh/react/api/createConfig). | ||
|
|
||
| <Tabs> | ||
| <TabItem value = "provider.ts"> | ||
|
|
||
| ```ts | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { ReactNode } from "react"; | ||
| import { WagmiProvider } from 'wagmi' | ||
| import { config } from "./config.ts"; | ||
|
|
||
| const queryClient = new QueryClient(); | ||
|
|
||
| export function AppProvider({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <WagmiProvider config={config}> | ||
| <QueryClientProvider client={queryClient}> | ||
| {children} | ||
| </QueryClientProvider> | ||
| </WagmiProvider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
|
|
||
| <TabItem value = "config.ts"> | ||
|
|
||
| ```ts | ||
| import { createConfig, http } from "wagmi"; | ||
| import { sepolia } from "viem/chains"; | ||
|
|
||
| export const config = createConfig({ | ||
| chains: [sepolia], | ||
| transports: { | ||
| [sepolia.id]: http(), | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ### 3. Create a smart account | ||
|
|
||
| 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 | ||
| MetaMask smart account. | ||
|
|
||
| ```ts | ||
| import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit"; | ||
| import { useAccount, usePublicClient, useWalletClient } from "wagmi"; | ||
|
|
||
| const { address } = useAccount(); | ||
| const publicClient = usePublicClient(); | ||
| const { data: walletClient } = useWalletClient(); | ||
|
|
||
| // Additional check to make sure the EOA wallet is connected | ||
| // and values are available. | ||
| if (!address || !walletClient || !publicClient ) { | ||
| // Handle the error case | ||
| } | ||
|
|
||
| const smartAccount = await toMetaMaskSmartAccount({ | ||
| client: publicClient, | ||
| implementation: Implementation.Hybrid, | ||
| deployParams: [address, [], [], []], | ||
| deploySalt: "0x", | ||
| signer: { walletClient }, | ||
| }); | ||
| ``` | ||
|
|
||
| ## Next steps | ||
|
|
||
| - See how to use [MetaMask Embedded Wallets as a signer](./eoa-wallets.md) to make user onboarding journey easier. | ||
| - See how to [send a user operations](../send-user-operation.md). | ||
| - To sponsor gas for end users, see how to [send a gasless transaction](../send-gasless-transaction.md). | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.