Skip to content

Commit 01a3ec9

Browse files
Adds signer guide for Privy
* minor hot fix * add privy as a signer guide * update sidebar * add index page for configuring signers * Apply suggestions from code review Co-authored-by: m4sterbunny <[email protected]> --------- Co-authored-by: m4sterbunny <[email protected]>
1 parent 1e8ad93 commit 01a3ec9

File tree

7 files changed

+192
-12
lines changed

7 files changed

+192
-12
lines changed

gator-sidebar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ const sidebar = {
6161
{
6262
type: 'category',
6363
label: 'Configure signers',
64+
link: { type: "doc", id: "guides/smart-accounts/signers/index" },
6465
collapsed: true,
6566
items: [
6667
'guides/smart-accounts/signers/dynamic',
6768
'guides/smart-accounts/signers/embedded-wallets',
69+
'guides/smart-accounts/signers/privy',
6870
],
6971
},
7072
],

gator_versioned_docs/version-0.1.0/guides/delegation/use-delegation-scopes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ keywords: [delegation scope, delegation, restrict, authority]
55

66
# Use delegation scopes
77

8-
When [creating a delegation](../execute-on-smart-accounts-behalf.md), you can configure a scope to define the delegation's initial authority and help prevent delegation misuse.
8+
When [creating a delegation](../execute-on-smart-accounts-behalf.md), you must configure a scope to define the delegation's initial authority and help prevent delegation misuse.
99
You can further constrain this initial authority by [adding caveats to a delegation](constrain-scope.md).
1010

1111
The Smart Accounts Kit currently supports three categories of scopes:

smart-accounts-kit/guides/delegation/use-delegation-scopes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ keywords: [delegation scope, delegation, restrict, authority]
55

66
# Use delegation scopes
77

8-
When [creating a delegation](../execute-on-smart-accounts-behalf.md), you can configure a scope to define the delegation's initial authority and help prevent delegation misuse.
8+
When [creating a delegation](../execute-on-smart-accounts-behalf.md), you must configure a scope to define the delegation's initial authority and help prevent delegation misuse.
99
You can further constrain this initial authority by [adding caveats to a delegation](constrain-scope.md).
1010

1111
The Smart Accounts Kit currently supports three categories of scopes:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ npm install @dynamic-labs/ethereum @dynamic-labs/sdk-react-core @dynamic-labs/wa
3535

3636
### 2. Create the Dynamic provider
3737

38-
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
38+
In this step, you'll configure the [`DynamicContextProvider`](https://www.dynamic.xyz/docs/react-sdk/providers/providers-introduction#dynamic-context-provider) component to provide Dynamic's context
3939
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
4040
connector enables you to use Wagmi hooks with Dynamic.
4141

4242
Once you have created the `DynamicProvider`, you must wrap it at the root of your application so
43-
that the rest of your application has access to the Dynamic context.
43+
that the rest of your application has access to the Dynamic's context.
4444

4545
For the advance configuration, see how to [configure Dynamic & Wagmi](https://www.dynamic.xyz/docs/react-sdk/using-wagmi).
4646

@@ -113,7 +113,7 @@ const { address } = useAccount();
113113
const publicClient = usePublicClient();
114114
const { data: walletClient } = useWalletClient();
115115

116-
// Additional check to make sure the Dyanmic wallet is connected
116+
// Additional check to make sure the Dyanmic is connected
117117
// and values are available.
118118
if (!address || !walletClient || !publicClient ) {
119119
// Handle the error case

smart-accounts-kit/guides/smart-accounts/signers/embedded-wallets.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This guide is targeted towards React and React-based frameworks.
2121
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later
2222
- Install [Yarn](https://yarnpkg.com/),
2323
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager
24-
- A [Embedded Wallets (Web3Auth) Client ID](/embedded-wallets/dashboard)
24+
- An [Embedded Wallets Client ID](/embedded-wallets/dashboard)
2525

2626
## Steps
2727

@@ -37,7 +37,7 @@ npm install @metamask/smart-accounts-kit @web3auth/modal wagmi @tanstack/react-q
3737

3838
Configure the `Web3AuthProvider` component to provide the Embedded Wallets context to your application.
3939
You'll also use the `WagmiProvider` to integrate Embedded Wallets with Wagmi.
40-
This connector enables you to use Wagmi hooks with Embedded Wallets.
40+
This provider enables you to use Wagmi hooks with Embedded Wallets.
4141

4242
Once you've created the `Web3AuthAppProvider`, wrap it at the root of your application so
4343
that the rest of your application has access to the Embedded Wallets context.
@@ -51,6 +51,7 @@ For the advance configuration, see [Embedded Wallets guide](https://docs.metamas
5151
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5252
import { ReactNode } from "react";
5353
import { Web3AuthProvider } from "@web3auth/modal/react";
54+
// Make sure to import `WagmiProvider` from `@web3auth/modal/react/wagmi`, not `wagmi`
5455
import { WagmiProvider } from "@web3auth/modal/react/wagmi";
5556
import { web3authConfig } from "./config.ts";
5657

@@ -72,12 +73,11 @@ export function Web3AuthAppProvider({ children }: { children: ReactNode }) {
7273
<TabItem value = "config.ts">
7374

7475
```ts
75-
import { WEB3AUTH_NETWORK_TYPE, Web3AuthOptions } from "@web3auth/modal";
76+
import { Web3AuthOptions } from "@web3auth/modal";
7677

7778
const web3AuthOptions: Web3AuthOptions = {
78-
clientId: process.env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID as string,
79-
web3AuthNetwork: process.env
80-
.NEXT_PUBLIC_WEB3AUTH_NETWORK as WEB3AUTH_NETWORK_TYPE,
79+
clientId: "<YOUR_WEB3AUTH_CLIENT_ID>",
80+
web3AuthNetwork: "<YOUR_WEB3AUTH_NETWORK>",
8181
};
8282

8383
export const web3authConfig = {
@@ -101,7 +101,7 @@ const { address } = useAccount();
101101
const publicClient = usePublicClient();
102102
const { data: walletClient } = useWalletClient();
103103

104-
// Additional check to make sure the Dyanmic wallet is connected
104+
// Additional check to make sure the Embedded Wallets is connected
105105
// and values are available.
106106
if (!address || !walletClient || !publicClient ) {
107107
// Handle the error case
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
description: Learn how to configure signers for MetaMask Smart Accounts.
3+
keywords: [signers, metamask smart accounts, smart account, embedded wallets, web3auth, dynamic, privy]
4+
---
5+
6+
import CardList from "@site/src/components/CardList"
7+
8+
# Configure a signer
9+
10+
When [creating a smart account](../create-smart-account.md), you must specify a signer. The signer owns the smart account and is responsible for
11+
generating the signatures required to submit user operations. MetaMask Smart Accounts is signer agnostic, allowing you
12+
to use any signer you prefer such as Embedded Wallets, Passkeys, EOA wallets, or a custom signer.
13+
14+
MetaMask Smart Accounts has native integration with [MetaMask Embedded Wallets](/embedded-wallets/), making it seamless to use smart
15+
accounts with embedded wallets and make user onboarding easier. In addition to native native integration, you can also use
16+
third-party wallet providers as Privy, Dynamic, or Para as the signer for your smart account.
17+
18+
Checkout the following guides to learn how to configure different signers:
19+
20+
## Recommended
21+
22+
<CardList items={[
23+
{
24+
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/embedded-wallets/",
25+
title: "MetaMask Embedded Wallets",
26+
description: "Learn how to use MetaMask Embedded Wallets (Web3Auth) with MetaMask Smart Accounts.",
27+
}
28+
]}/>
29+
30+
## More
31+
32+
<CardList items={[
33+
{
34+
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/dynamic",
35+
title: "Dynamic",
36+
description: "Learn how to use Dynamic with MetaMask Smart Accounts.",
37+
},
38+
{
39+
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/privy",
40+
title: "Privy",
41+
description: "Learn how to use Privy with MetaMask Smart Accounts.",
42+
}
43+
]}/>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
description: Learn how to use Privy signer with MetaMask Smart Accounts.
3+
sidebar_label: Privy
4+
keywords: [privy, smart account, signer, metamask smart account]
5+
---
6+
7+
# Use Privy with MetaMask Smart Accounts
8+
9+
[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
10+
that allows you to use Privy's EOA wallet as a signer for MetaMask Smart Accounts.
11+
12+
:::info
13+
This guide is targeted towards React and React-based frameworks.
14+
:::
15+
16+
## Prerequisites
17+
18+
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
19+
- Install [Yarn](https://yarnpkg.com/),
20+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager
21+
- A [Privy App ID](https://docs.privy.io/basics/get-started/dashboard/create-new-app#get-api-credentials)
22+
23+
## Steps
24+
25+
### 1. Install dependencies
26+
27+
Install the following dependencies:
28+
29+
```bash npm2yarn
30+
npm install @privy-io/react-auth @privy-io/wagmi @metamask/smart-accounts-kit @tanstack/react-query wagmi viem
31+
```
32+
33+
### 2. Create the Privy provider
34+
35+
In this step, you'll configure the `PrivyProvider` component to provide the Privy's context
36+
to your application. You'll also use the Privy's `WagmiProvider` component to integrate Privy with Wagmi. This
37+
provider enables you to use Wagmi hooks with Privy.
38+
39+
Once you have created the `PrivyAppProvider`, you must wrap it at the root of your application so
40+
that the rest of your application has access to the Privy's context.
41+
42+
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.
43+
44+
<Tabs>
45+
<TabItem value = "provider.ts">
46+
47+
```ts
48+
import { QueryClientProvider } from "@tanstack/react-query";
49+
import { ReactNode } from "react";
50+
import { PrivyProvider } from '@privy-io/react-auth';
51+
// Make sure to import `WagmiProvider` from `@privy-io/wagmi`, not `wagmi`
52+
import { WagmiProvider } from '@privy-io/wagmi';
53+
import { QueryClientProvider } from '@tanstack/react-query';
54+
import { wagmiConfig, queryClient, privyConfig } from "./config.ts"
55+
56+
export function PrivyAppProvider({ children }: { children: ReactNode }) {
57+
return (
58+
<PrivyProvider appId="<YOUR_PRIVY_APP_ID>" config={privyConfig}>
59+
<QueryClientProvider client={queryClient}>
60+
<WagmiProvider config={wagmiConfig}>
61+
{children}
62+
</WagmiProvider>
63+
</QueryClientProvider>
64+
</PrivyProvider>
65+
);
66+
}
67+
```
68+
69+
</TabItem>
70+
71+
<TabItem value = "config.ts">
72+
73+
```ts
74+
import type { PrivyClientConfig } from '@privy-io/react-auth';
75+
import { QueryClient } from "@tanstack/react-query";
76+
import { createConfig, http } from "wagmi";
77+
import { sepolia } from "viem/chains";
78+
79+
export const queryClient = new QueryClient();
80+
81+
export const wagmiConfig = createConfig({
82+
chains: [sepolia],
83+
ssr: true,
84+
transports: {
85+
[sepolia.id]: http(),
86+
},
87+
});
88+
89+
export const privyConfig: PrivyClientConfig = {
90+
embeddedWallets: {
91+
createOnLogin: 'users-without-wallets',
92+
showWalletUIs: true
93+
},
94+
loginMethods: ['wallet', 'email', 'sms'],
95+
appearance: {
96+
showWalletLoginFirst: true
97+
}
98+
};
99+
```
100+
101+
</TabItem>
102+
</Tabs>
103+
104+
### 3. Create a smart account
105+
106+
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
107+
MetaMask smart account.
108+
109+
```ts
110+
import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit";
111+
import { useAccount, usePublicClient, useWalletClient } from "wagmi";
112+
113+
const { address } = useAccount();
114+
const publicClient = usePublicClient();
115+
const { data: walletClient } = useWalletClient();
116+
117+
// Additional check to make sure the Privy is connected
118+
// and values are available.
119+
if (!address || !walletClient || !publicClient ) {
120+
// Handle the error case
121+
}
122+
123+
const smartAccount = await toMetaMaskSmartAccount({
124+
client: publicClient,
125+
implementation: Implementation.Hybrid,
126+
deployParams: [address, [], [], []],
127+
deploySalt: "0x",
128+
signer: { walletClient },
129+
});
130+
```
131+
132+
## Next steps
133+
134+
- See how to [send a user operation](../send-user-operation.md).
135+
- To sponsor gas for end users, see how to [send a gasless transaction](../send-gasless-transaction.md).

0 commit comments

Comments
 (0)