-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Smart Accounts Kit] Add guide for Privy #2570
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3099943
minor hot fix
AyushBherwani1998 321779e
add privy as a signer guide
AyushBherwani1998 33797da
update sidebar
AyushBherwani1998 19c1f12
add index page for configuring signers
AyushBherwani1998 1e3dea3
Merge branch 'main' into feat/privy-signer
AyushBherwani1998 1fc5063
Apply suggestions from code review
AyushBherwani1998 94c7666
Merge branch 'main' into feat/privy-signer
AyushBherwani1998 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
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
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
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
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
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,43 @@ | ||
| --- | ||
| description: Learn how to configure signers for MetaMask Smart Accounts. | ||
| keywords: [signers, metamask smart accounts, smart account, embedded wallets, web3auth, dynamic, privy] | ||
| --- | ||
|
|
||
| import CardList from "@site/src/components/CardList" | ||
|
|
||
| # Configure a signer | ||
|
|
||
| When [creating a smart account](../create-smart-account.md), you must specify a signer. The signer owns the smart account and is responsible for | ||
| generating the signatures required to submit user operations. MetaMask Smart Accounts is signer agnostic, allowing you | ||
| to use any signer you prefer such as Embedded Wallets, Passkeys, EOA wallets, or a custom signer. | ||
|
|
||
| MetaMask Smart Accounts has native integration with [MetaMask Embedded Wallets](/embedded-wallets/), making it seamless to use smart | ||
| accounts with embedded wallets and make user onboarding easier. In addition to native native integration, you can also use | ||
| third-party wallet providers as Privy, Dynamic, or Para as the signer for your smart account. | ||
|
|
||
| Checkout the following guides to learn how to configure different signers: | ||
|
|
||
| ## Recommended | ||
|
|
||
| <CardList items={[ | ||
| { | ||
| href: "/smart-accounts-kit/development/guides/smart-accounts/signers/embedded-wallets/", | ||
| title: "MetaMask Embedded Wallets", | ||
| description: "Learn how to use MetaMask Embedded Wallets (Web3Auth) with MetaMask Smart Accounts.", | ||
| } | ||
| ]}/> | ||
|
|
||
| ## More | ||
|
|
||
| <CardList items={[ | ||
| { | ||
| href: "/smart-accounts-kit/development/guides/smart-accounts/signers/dynamic", | ||
| title: "Dynamic", | ||
| description: "Learn how to use Dynamic with MetaMask Smart Accounts.", | ||
| }, | ||
| { | ||
| href: "/smart-accounts-kit/development/guides/smart-accounts/signers/privy", | ||
| title: "Privy", | ||
| description: "Learn how to use Privy with MetaMask Smart Accounts.", | ||
| } | ||
| ]}/> |
135 changes: 135 additions & 0 deletions
135
smart-accounts-kit/guides/smart-accounts/signers/privy.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,135 @@ | ||
| --- | ||
| description: Learn how to use Privy signer with MetaMask Smart Accounts. | ||
| sidebar_label: Privy | ||
| keywords: [privy, smart account, signer, metamask smart account] | ||
| --- | ||
|
|
||
| # Use Privy with MetaMask Smart Accounts | ||
|
|
||
| [Privy](https://docs.privy.io/welcome) provides an embedded wallet solution that enables seamless social login for Web3 applications making user onboarding easier. MetaMask Smart Accounts is a signer agnostic implementation | ||
| that allows you to use Privy's EOA wallet as a signer for MetaMask Smart Accounts. | ||
|
|
||
| :::info | ||
| This guide is targeted towards React and React-based frameworks. | ||
AyushBherwani1998 marked this conversation as resolved.
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 | ||
| - A [Privy App ID](https://docs.privy.io/basics/get-started/dashboard/create-new-app#get-api-credentials) | ||
|
|
||
| ## Steps | ||
|
|
||
| ### 1. Install dependencies | ||
|
|
||
| Install the following dependencies: | ||
|
|
||
| ```bash npm2yarn | ||
| npm install @privy-io/react-auth @privy-io/wagmi @metamask/smart-accounts-kit @tanstack/react-query wagmi viem | ||
| ``` | ||
|
|
||
| ### 2. Create the Privy provider | ||
|
|
||
| In this step, you'll configure the `PrivyProvider` component to provide the Privy's context | ||
| to your application. You'll also use the Privy's `WagmiProvider` component to integrate Privy with Wagmi. This | ||
| provider enables you to use Wagmi hooks with Privy. | ||
|
|
||
| Once you have created the `PrivyAppProvider`, you must wrap it at the root of your application so | ||
| that the rest of your application has access to the Privy's context. | ||
|
|
||
| For the advance configuration, see Privy's [configuring appearance](https://docs.privy.io/basics/get-started/dashboard/configuring-appearance) and [configuring login methods](https://docs.privy.io/basics/get-started/dashboard/configure-login-methods) guide. | ||
|
|
||
| <Tabs> | ||
| <TabItem value = "provider.ts"> | ||
|
|
||
| ```ts | ||
| import { QueryClientProvider } from "@tanstack/react-query"; | ||
| import { ReactNode } from "react"; | ||
| import { PrivyProvider } from '@privy-io/react-auth'; | ||
| // Make sure to import `WagmiProvider` from `@privy-io/wagmi`, not `wagmi` | ||
| import { WagmiProvider } from '@privy-io/wagmi'; | ||
| import { QueryClientProvider } from '@tanstack/react-query'; | ||
| import { wagmiConfig, queryClient, privyConfig } from "./config.ts" | ||
|
|
||
| export function PrivyAppProvider({ children }: { children: ReactNode }) { | ||
| return ( | ||
| <PrivyProvider appId="<YOUR_PRIVY_APP_ID>" config={privyConfig}> | ||
| <QueryClientProvider client={queryClient}> | ||
| <WagmiProvider config={wagmiConfig}> | ||
| {children} | ||
| </WagmiProvider> | ||
| </QueryClientProvider> | ||
| </PrivyProvider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| </TabItem> | ||
|
|
||
| <TabItem value = "config.ts"> | ||
|
|
||
| ```ts | ||
| import type { PrivyClientConfig } from '@privy-io/react-auth'; | ||
| import { QueryClient } from "@tanstack/react-query"; | ||
| import { createConfig, http } from "wagmi"; | ||
| import { sepolia } from "viem/chains"; | ||
|
|
||
| export const queryClient = new QueryClient(); | ||
|
|
||
| export const wagmiConfig = createConfig({ | ||
| chains: [sepolia], | ||
| ssr: true, | ||
| transports: { | ||
| [sepolia.id]: http(), | ||
| }, | ||
| }); | ||
|
|
||
| export const privyConfig: PrivyClientConfig = { | ||
| embeddedWallets: { | ||
| createOnLogin: 'users-without-wallets', | ||
| showWalletUIs: true | ||
| }, | ||
| loginMethods: ['wallet', 'email', 'sms'], | ||
| appearance: { | ||
| showWalletLoginFirst: true | ||
| } | ||
| }; | ||
| ``` | ||
|
|
||
| </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 Privy 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 [send a user operation](../send-user-operation.md). | ||
| - To sponsor gas for end users, see how to [send a gasless transaction](../send-gasless-transaction.md). | ||
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.