-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Smart Accounts Kit] Add guide for Dynamic #2567
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
Changes from 1 commit
d2b3f2e
3334767
a51321f
5cf4f2e
9578808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,128 @@ | ||||||||||||||||||||
| --- | ||||||||||||||||||||
| description: Learn how to use Dynamic signer with MetaMask Smart Accounts. | ||||||||||||||||||||
| sidebar_label: Dynamic | ||||||||||||||||||||
| keywords: [dynamic, smart account, signer, metamask samrt account] | ||||||||||||||||||||
| --- | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Use Dynamic with MetaMask Smart Accounts | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Dynamic](https://www.dynamic.xyz/) is an embedded wallet solution that enables seamless social login and passkey based | ||||||||||||||||||||
bgravenorst marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| wallets, making user onboarding easier. MetaMask Smart Accounts is a signer agnostic implementation | ||||||||||||||||||||
| that allows you to use Dynamic's EOA wallet as a signer for MetaMask Smart Accounts. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| View the complete code for this guide at [gator-examples repository](https://github.com/MetaMask/gator-examples/tree/main/examples/smart-accounts/signers/dynamic). | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Prerequisites | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already mentioned, also react app is not Prerequisite. They can use any framework React, Next JS, etc.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed a commit for Node.js requirement.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dependencies presented in the guide are specifically related to react: @dynamic-labs/sdk-react-core
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an info note at top of the guide to make sure readers are aware. |
||||||||||||||||||||
| - Install [Yarn](https://yarnpkg.com/), | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldnt even bother mentioning yarn, given that the bash example is for npm, the "such as" can do the "go do this with yarn if that pleases you" part
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, my laser focus! I would still just such as and mention 1 ... everyone has a fav, so the important part is "package manager"
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We follow this pattern through out the docs and it's been working so far, so would prefer keeping same. |
||||||||||||||||||||
| [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already mentioned above.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per comment |
||||||||||||||||||||
| - [Create a Dynamic Environment ID](https://www.dynamic.xyz/docs/developer-dashboard/tokens-api-keys#environment-id) | ||||||||||||||||||||
AyushBherwani1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| ## Steps | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ### 1. Install dependencies | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Install the following dependencies: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ```bash npm2yarn | ||||||||||||||||||||
| npm install @dynamic-labs/ethereum @dynamic-labs/sdk-react-core @dynamic-labs/wagmi-connector @metamask/smart-accounts-kit @tanstack/react-query wagmi viem | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ### 2. Create the Dynamic provider | ||||||||||||||||||||
|
|
||||||||||||||||||||
| In this step, you'll configure the [`DynamicContextProvider`](https://www.dynamic.xyz/docs/react-sdk/providers/providers-introduction#dynamic-context-provider) component to provide the Dynamic context | ||||||||||||||||||||
| to your application. You'll also use the [`DynamicWagmiConnector`](https://www.dynamic.xyz/docs/react-sdk/providers/providers-introduction#dynamic-wagmi-connector) to integrate Dynamic with Wagmi. This | ||||||||||||||||||||
| connector enables you to use Wagmi hooks with Dynamic. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Once you have created the `DynamicProvider`, you must wrap it at the root of your application so | ||||||||||||||||||||
| that the rest of your application has access to the Dynamic context. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| For the advance configuration, see how to [configure Dynamic & Wagmi](https://www.dynamic.xyz/docs/react-sdk/using-wagmi). | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <Tabs> | ||||||||||||||||||||
| <TabItem value = "provider.ts"> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ```ts | ||||||||||||||||||||
| import { QueryClientProvider } from "@tanstack/react-query"; | ||||||||||||||||||||
| import { WagmiProvider } from "wagmi"; | ||||||||||||||||||||
| import { ReactNode } from "react"; | ||||||||||||||||||||
| import { EthereumWalletConnectors } from "@dynamic-labs/ethereum"; | ||||||||||||||||||||
| import { DynamicContextProvider } from "@dynamic-labs/sdk-react-core"; | ||||||||||||||||||||
| import { DynamicWagmiConnector } from "@dynamic-labs/wagmi-connector"; | ||||||||||||||||||||
| import { wagmiConfig, queryClient } from "./config.ts" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export function DynamicProvider({ children }: { children: ReactNode }) { | ||||||||||||||||||||
| return ( | ||||||||||||||||||||
| <DynamicContextProvider | ||||||||||||||||||||
| settings={{ | ||||||||||||||||||||
| // Get your environment id at https://app.dynamic.xyz/dashboard/developer | ||||||||||||||||||||
| environmentId: "YOUR_DYNAMIC_ENVIRONMENT_ID", | ||||||||||||||||||||
AyushBherwani1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||
| walletConnectors: [EthereumWalletConnectors], | ||||||||||||||||||||
| }} | ||||||||||||||||||||
| > | ||||||||||||||||||||
| <QueryClientProvider client={queryClient}> | ||||||||||||||||||||
| <WagmiProvider config={wagmiConfig}> | ||||||||||||||||||||
| <DynamicWagmiConnector> | ||||||||||||||||||||
| {children} | ||||||||||||||||||||
| </DynamicWagmiConnector> | ||||||||||||||||||||
| </WagmiProvider> | ||||||||||||||||||||
| </QueryClientProvider> | ||||||||||||||||||||
| </DynamicContextProvider > | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| </TabItem> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <TabItem value = "config.ts"> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ```ts | ||||||||||||||||||||
| 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(), | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| </TabItem> | ||||||||||||||||||||
| </Tabs> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ### 3. Create a smart account | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Once the user has connected their wallet, you can use the [Wallet Client](https://viem.sh/docs/clients/wallet) from Wagmi as the signer to create a | ||||||||||||||||||||
AyushBherwani1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||
| 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 Dyanmic 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 | ||||||||||||||||||||
AyushBherwani1998 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| - See how to [send a user operations](../send-user-operation.md). | ||||||||||||||||||||
AyushBherwani1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||
| - To sponsor gas for end users, see how to [send a gasless transaction](../send-gasless-transaction.md). | ||||||||||||||||||||

Uh oh!
There was an error while loading. Please reload this page.