Skip to content

Commit bc05af3

Browse files
🔄 synced file(s) with circlefin/modularwallets-web-sdk-internal (#8)
synced local file(s) with [circlefin/modularwallets-web-sdk-internal](https://github.com/circlefin/modularwallets-web-sdk-internal). <details> <summary>Changed files</summary> <ul> <li>synced local directory <code>examples/</code> with remote directory <code>examples/</code></li><li>synced local directory <code>packages/</code> with remote directory <code>packages/</code></li><li>synced local directory <code>templates/</code> with remote directory <code>templates/</code></li><li>synced local <code>package.json</code> with remote <code>package.json</code></li><li>synced local <code>README.md</code> with remote <code>README.md</code></li><li>created local <code>pnpm-lock.yaml</code> from remote <code>pnpm-lock.yaml</code></li><li>created local <code>pnpm-workspace.yaml</code> from remote <code>pnpm-workspace.yaml</code></li> </ul> </details> --- This PR was created automatically by the [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) workflow run [#14201423206](https://github.com/circlefin/modularwallets-web-sdk-internal/actions/runs/14201423206)
1 parent 00b4e83 commit bc05af3

File tree

74 files changed

+16629
-2634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+16629
-2634
lines changed

‎README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@ Confirm that you are using the correct Node.js version listed in the `.nvmrc` fi
3333
node -v
3434
```
3535

36-
This project uses `yarn` to install dependencies, please ensure you have it installed.
36+
This project uses `pnpm` to install dependencies, please ensure you have it installed.
3737

3838
> [!TIP]
39-
> Since Node.js v14.19, you can use the [corepack](https://github.com/nodejs/corepack) command to enable `yarn`:
39+
> Since Node.js v16.13, you can use the [corepack](https://github.com/nodejs/corepack) command to enable `pnpm`:
4040
>
4141
> ```zsh
42-
> corepack enable
42+
> corepack enable pnpm
4343
> ```
4444
45-
You can confirm that you have `yarn` installed with:
45+
You can confirm that you have `pnpm` installed with:
4646
4747
```zsh
48-
yarn -v
48+
pnpm -v
4949
```
5050
51-
You can now install the project dependencies using `yarn`:
51+
You can now install the project dependencies using `pnpm`:
5252

5353
```zsh
54-
yarn install
54+
pnpm install
5555
```
5656

5757
> [!TIP]
58-
> It is good practice to run the `yarn install` command every time dependencies in the `package.json` are changed when updating your branch
58+
> It is good practice to run the `pnpm install` command every time dependencies in the `package.json` are changed when updating your branch
5959
6060
#### Example: installing a node version manager
6161

@@ -76,19 +76,19 @@ nvm use
7676
To lint the project:
7777

7878
```zsh
79-
yarn lint
79+
pnpm lint
8080
```
8181

8282
### Test
8383

8484
To run all unit tests, run:
8585

8686
```zsh
87-
yarn test
87+
pnpm test
8888
```
8989

9090
To generate coverage reports:
9191

9292
```zsh
93-
yarn test:coverage
93+
pnpm test:coverage
9494
```

‎examples/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@
33
We will keep adding examples to this directory to demonstrate how our SDK can be used in different use cases.
44

55
Please check out each example's README file to get started!
6+
7+
## Important: Using Workspaces
8+
9+
This project uses pnpm workspaces. Before running any example project, you need to build the SDK packages from the project root:
10+
11+
```bash
12+
# From the project root directory
13+
pnpm build
14+
```
15+
16+
This will generate the necessary distribution files that the example projects depend on.

‎examples/circle-smart-account/README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,20 @@ Once you have these environment variables setup, you can now follow the steps be
2424
You first need to make sure you have followed the [README](https://github.com/circlefin/modularwallets-web-sdk/blob/master/README.md) under project root and have installed all dependencies under root folder:
2525

2626
```bash
27-
$ yarn install
27+
$ pnpm install
2828
```
2929

30+
#### Important: Build the SDK
31+
32+
Since this project uses pnpm workspaces, you must build the SDK packages before running the example:
33+
34+
```bash
35+
# From the project root directory
36+
$ pnpm build
37+
```
38+
39+
This will generate the necessary distribution files that this example depends on.
40+
3041
Now you need to go to this example folder:
3142

3243
```bash
@@ -36,33 +47,21 @@ $ cd examples/circle-smart-account
3647
Once you are under the example folder, install all dependencies for the app:
3748

3849
```bash
39-
$ yarn install
50+
$ pnpm install
4051
```
4152

4253
### Run the app
4354

4455
To run the app locally:
4556

4657
```bash
47-
$ yarn dev
58+
$ pnpm dev
4859
```
4960

5061
Now you should be able to see your app up and running in your browser at: `http://localhost:5173/`.
5162

5263
### Important Notes
5364

54-
- __Do Not Import from `src` or `dist` Directories Directly:__
55-
56-
Always import the Core SDK using the package name:
57-
58-
```ts
59-
import { yourFunction } from 'w3s-web-core-sdk'
60-
```
61-
62-
- __Watching Changes from the Core SDK Package__
63-
64-
If you are developing new SDK features, run `yarn dev` from the [core SDK package directory](../../packages/w3s-web-core-sdk) to build your changes in real time.
65-
66-
- __Ensure Build-Time Constants Are Replaced:__
65+
- **Ensure the installed SDK version is greater than or equal to `1.0.3`:**
6766

68-
Variables like `SDK_VERSION` should be replaced during the build process. If you encounter issues, make sure you're using the compiled code from the dist directory.
67+
If you receive an error message that says `Address mismatch` in the example app, make sure you are using the correct version of the SDK as we updated the MSCAUpgradable smart contract implementation in version `1.0.3`. This error occurs when the SDK version is less than `1.0.3`.

‎examples/circle-smart-account/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"dev": "vite"
88
},
99
"dependencies": {
10+
"@circle-fin/modular-wallets-core": "workspace:*",
1011
"react": "^18.2.0",
1112
"react-dom": "^18.2.0",
12-
"viem": "^2.21.27",
13-
"@circle-fin/modular-wallets-core": "^1.x.x"
13+
"viem": "^2.21.27"
1414
},
1515
"devDependencies": {
1616
"@types/react": "^18.0.27",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_CLIENT_KEY=
2+
VITE_CLIENT_URL=
3+
VITE_DYNAMIC_ENV_ID=
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from "react"
2+
import * as ReactDOM from "react-dom/client"
3+
4+
import { EthereumWalletConnectors } from "@dynamic-labs/ethereum"
5+
import { DynamicContextProvider, DynamicWidget } from "@dynamic-labs/sdk-react-core"
6+
7+
import { Example } from "."
8+
9+
const environmentId = import.meta.env.VITE_DYNAMIC_ENV_ID as string
10+
11+
function App() {
12+
return (
13+
<DynamicContextProvider
14+
settings={{
15+
environmentId,
16+
walletConnectors: [EthereumWalletConnectors],
17+
}}
18+
>
19+
<DynamicWidget variant="modal" />
20+
<Example />
21+
</DynamicContextProvider>
22+
)
23+
}
24+
25+
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(<App />)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Dynamic Integration Example
2+
3+
This example Vite application demonstrates how to integrate [Dynamic](https://www.dynamic.xyz/)'s SDK using an EOA account.
4+
5+
## Run the example app
6+
7+
Please follow the instructions to run the example app on your local machine.
8+
9+
### Environment Variables
10+
11+
Before you start to run the app, you need to make sure that all environment variables are configured correctly.
12+
13+
Make a copy of `.env.example` and rename it to `.env`.
14+
15+
Under `.env`, make sure the following environment variables are configured properly:
16+
17+
- `VITE_CLIENT_KEY`: Paste your Client Key here. You can create one in [Circle Developer Console](https://console.circle.com/wallets/modular/configurator).
18+
- `VITE_CLIENT_URL`: Paste the Client URL here. You can copy it from [Circle Developer Console](https://console.circle.com/wallets/modular/configurator).
19+
- `VITE_DYNAMIC_ENV_ID`: Paste the Dynamic Environment ID here. You can copy it from [Dynamic Console](https://app.dynamic.xyz/dashboard/overview).
20+
21+
Once you have these environment variables setup, you can now follow the steps below to run the app locally.
22+
23+
### Install dependencies
24+
25+
You first need to make sure you have followed the [README](https://github.com/circlefin/w3s-web-core-sdk/blob/master/README.md) under project root and have installed all dependencies under root folder:
26+
27+
```bash
28+
$ pnpm install
29+
```
30+
31+
#### Important: Build the SDK
32+
33+
Since this project uses pnpm workspaces, you must build the SDK packages before running the example:
34+
35+
```bash
36+
# From the project root directory
37+
$ pnpm build
38+
```
39+
40+
This will generate the necessary distribution files that this example depends on.
41+
42+
Now you need to go to this example folder:
43+
44+
```bash
45+
$ cd examples/dynamic-integration
46+
```
47+
48+
Once you are under the example folder, install all dependencies for the app:
49+
50+
```bash
51+
$ pnpm install
52+
```
53+
54+
### Run the app
55+
56+
To run the app locally:
57+
58+
```bash
59+
$ pnpm dev
60+
```
61+
62+
Now you should be able to see your app up and running in your browser at: `http://localhost:5173/`.
63+
64+
### Important Notes
65+
66+
- **Ensure the installed SDK version is greater than or equal to `1.0.3`:**
67+
68+
If you receive an error message that says `Address mismatch` in the example app, make sure you are using the correct version of the SDK as we updated the MSCAUpgradable smart contract implementation in version `1.0.3`. This error occurs when the SDK version is less than `1.0.3`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
</head>
7+
<body>
8+
<h1>Dynamic Integration Example</h1>
9+
<div id="root"></div>
10+
<script type="module" src="/App.tsx"></script>
11+
</body>
12+
</html>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import React, { useEffect } from "react"
2+
import { createPublicClient, Hex, parseEther } from "viem"
3+
4+
import { isEthereumWallet } from "@dynamic-labs/ethereum"
5+
import { useDynamicContext } from "@dynamic-labs/sdk-react-core"
6+
import { toCircleSmartAccount, toModularTransport, walletClientToLocalAccount } from "modular-wallets-core"
7+
import { createBundlerClient, SmartAccount } from "viem/account-abstraction"
8+
import { polygonAmoy } from "viem/chains"
9+
10+
const clientKey = import.meta.env.VITE_CLIENT_KEY as string
11+
const clientUrl = import.meta.env.VITE_CLIENT_URL as string
12+
13+
// Create Circle transports
14+
const modularTransport = toModularTransport(`${clientUrl}/polygonAmoy`, clientKey)
15+
16+
// Create a public client
17+
const client = createPublicClient({
18+
chain: polygonAmoy,
19+
transport: modularTransport,
20+
})
21+
22+
// Create a bundler client
23+
const bundlerClient = createBundlerClient({
24+
chain: polygonAmoy,
25+
transport: modularTransport,
26+
})
27+
28+
export const Example = () => {
29+
const { primaryWallet } = useDynamicContext() // Get the wallet information from the Dynamic context provider
30+
const [account, setAccount] = React.useState<SmartAccount>()
31+
const [hash, setHash] = React.useState<Hex>()
32+
const [userOpHash, setUserOpHash] = React.useState<Hex>()
33+
34+
useEffect(() => {
35+
setSigner()
36+
37+
async function setSigner() {
38+
if (primaryWallet == null) {
39+
// Reset the account if the wallet is not connected
40+
setAccount(undefined)
41+
42+
return
43+
}
44+
45+
if (!isEthereumWallet(primaryWallet)) {
46+
throw new Error("This wallet is not an Ethereum wallet")
47+
}
48+
49+
const dynamicProvider = await primaryWallet.getWalletClient()
50+
51+
toCircleSmartAccount({
52+
client,
53+
owner: walletClientToLocalAccount(dynamicProvider), // Transform the wallet client to a local account
54+
}).then(setAccount)
55+
}
56+
}, [primaryWallet])
57+
58+
const sendUserOperation = async (event: React.FormEvent<HTMLFormElement>) => {
59+
event.preventDefault()
60+
if (!account) return
61+
62+
const formData = new FormData(event.currentTarget)
63+
const to = formData.get("to") as `0x${string}`
64+
const value = formData.get("value") as string
65+
66+
const hash = await bundlerClient.sendUserOperation({
67+
account,
68+
calls: [
69+
{
70+
to,
71+
value: parseEther(value),
72+
},
73+
],
74+
paymaster: true,
75+
})
76+
setUserOpHash(hash)
77+
78+
const { receipt } = await bundlerClient.waitForUserOperationReceipt({
79+
hash,
80+
})
81+
setHash(receipt.transactionHash)
82+
}
83+
84+
if (!primaryWallet) {
85+
return null
86+
}
87+
88+
return (
89+
<div>
90+
{!account ? (
91+
<p>Loading...</p>
92+
) : (
93+
<>
94+
<p>Address: {account?.address}</p>
95+
<h2>Send User Operation</h2>
96+
<form onSubmit={sendUserOperation}>
97+
<input name="to" placeholder="Address" />
98+
<input name="value" placeholder="Amount (ETH)" />
99+
<button type="submit">Send</button>
100+
{userOpHash && <p>User Operation Hash: {userOpHash}</p>}
101+
{hash && <p>Transaction Hash: {hash}</p>}
102+
</form>
103+
</>
104+
)}
105+
</div>
106+
)
107+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "example-dynamic-integration",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite"
8+
},
9+
"dependencies": {
10+
"@circle-fin/modular-wallets-core": "workspace:*",
11+
"@dynamic-labs/ethereum": "^4.6.0",
12+
"@dynamic-labs/sdk-react-core": "^4.6.0",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"viem": "^2.21.27",
16+
"wagmi": "^2.14.11"
17+
},
18+
"devDependencies": {
19+
"@types/react": "^18.0.27",
20+
"@types/react-dom": "^18.0.10",
21+
"@vitejs/plugin-react": "^4.3.2",
22+
"typescript": "^5.0.3",
23+
"vite": "^5.4.14"
24+
}
25+
}

0 commit comments

Comments
 (0)