|
1 | 1 | --- |
2 | 2 | title: Migrating to Web3Auth PnP No Modal SDK v10 |
3 | 3 | description: |
4 | | - "Learn how to upgrade your Web3Auth PnP No Modal SDK from v9 to v10 with minimal changes and |
5 | | - cleaner architecture." |
| 4 | + Learn how to upgrade your Web3Auth PnP No Modal SDK from v9 to v10 with minimal changes and |
| 5 | + cleaner architecture. |
6 | 6 | sidebar_label: v9 to v10 |
7 | 7 | --- |
8 | 8 |
|
@@ -387,48 +387,165 @@ from `web3auth.provider`. |
387 | 387 |
|
388 | 388 | ## 6. Smart Accounts setup (optional) |
389 | 389 |
|
390 | | -Smart Accounts are now fully configurable via the Web3Auth Dashboard and optionally overridden |
391 | | -through the `accountAbstraction` parameter in the SDK options. |
| 390 | +Previously, configuring the adapter required installing the `@web3auth/account-abstraction-provider` |
| 391 | +package and using the `AccountAbstractionProvider` to set up the bundler, paymaster, and Smart |
| 392 | +Account Provider. |
392 | 393 |
|
393 | 394 | <Tabs> |
394 | 395 | <TabItem value="v9" label="v9 (before)"> |
395 | 396 |
|
396 | 397 | ```ts |
397 | | -// Example: v9 might involve initializing AccountAbstractionProvider |
398 | | -import { AccountAbstractionProvider } from "@web3auth/account-abstraction-provider"; |
| 398 | +import { |
| 399 | + AccountAbstractionProvider, |
| 400 | + SafeSmartAccount, |
| 401 | +} from "@web3auth/account-abstraction-provider"; |
| 402 | +import { Web3AuthNoModal, WEB3AUTH_NETWORK } from "@web3auth/no-modal"; // Assuming privateKeyProvider is also imported or available |
399 | 403 |
|
400 | | -// const web3auth = new Web3AuthNoModal({ /* ... */ }); |
401 | | -// await web3auth.init(); |
| 404 | +// Assume privateKeyProvider is initialized appropriately, e.g.: |
| 405 | +// import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider"; |
| 406 | +// const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { /* ... */ } }); |
| 407 | + |
| 408 | +// Assume pimlicoAPIKey is defined |
| 409 | +// const pimlicoAPIKey = "YOUR_PIMLICO_API_KEY"; |
| 410 | + |
| 411 | +// 1. Initialize Web3AuthNoModal first |
| 412 | +const web3auth = new Web3AuthNoModal({ |
| 413 | + clientId: "YOUR_WEB3AUTH_CLIENT_ID", |
| 414 | + web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, |
| 415 | + privateKeyProvider, // This should be an initialized PrivateKeyProvider |
| 416 | +}); |
| 417 | +await web3auth.init(); |
| 418 | +// Example: Connect to a login provider |
| 419 | +// await web3auth.connectTo(WALLET_CONNECTORS.OPENLOGIN, { /* loginProvider specific details */ }); |
| 420 | + |
| 421 | +// 2. Then initialize AccountAbstractionProvider with the provider from Web3AuthNoModal |
| 422 | +const chainConfig = { |
| 423 | + // Chain config (example placeholder, replace with actual v9 config) |
| 424 | + chainId: "0x1", // Example: Ethereum Mainnet |
| 425 | + rpcTarget: "https://rpc.ankr.com/eth", |
| 426 | + displayName: "Ethereum Mainnet", |
| 427 | + blockExplorerUrl: "https://etherscan.io/", |
| 428 | + ticker: "ETH", |
| 429 | + tickerName: "Ethereum", |
| 430 | +}; |
402 | 431 |
|
403 | | -// const aaProvider = new AccountAbstractionProvider(web3auth.provider, { /* config */ }); |
404 | | -// await aaProvider.init(); |
405 | | -// const smartAccountProvider = aaProvider.provider; |
| 432 | +if (web3auth.provider) { |
| 433 | + const accountAbstractionProvider = new AccountAbstractionProvider({ |
| 434 | + config: { |
| 435 | + chainConfig, |
| 436 | + smartAccountInit: new SafeSmartAccount(), |
| 437 | + bundlerConfig: { |
| 438 | + // Get the pimlico API Key from dashboard.pimlico.io |
| 439 | + url: `https://api.pimlico.io/v2/11155111/rpc?apikey=${"YOUR_PIMLICO_API_KEY_VARIABLE"}`, |
| 440 | + }, |
| 441 | + }, |
| 442 | + }); |
| 443 | + await accountAbstractionProvider.init(web3auth.provider); |
| 444 | + // const smartAccountProvider = accountAbstractionProvider.provider; |
| 445 | +} else { |
| 446 | + console.error("Web3Auth provider not available to initialize Smart Account provider."); |
| 447 | +} |
406 | 448 | ``` |
407 | 449 |
|
408 | 450 | </TabItem> |
409 | 451 | <TabItem value="v10" label="v10 (after)"> |
410 | 452 |
|
| 453 | +In v10, the `@web3auth/account-abstraction-provider` has been deprecated. You can now enable Smart |
| 454 | +Accounts and configure the bundler and paymaster directly from the Web3Auth Dashboard. See |
| 455 | +[Smart Accounts dashboard configuration](https://web3auth.io/docs/product-infrastructure/account-abstraction/dashboard-setup) |
| 456 | +to learn more. |
| 457 | + |
| 458 | +``` |
| 459 | +// Add Dashboard image (Placeholder for visual guide) |
| 460 | +``` |
| 461 | + |
| 462 | +If you want to override the Smart Account provider, bundler, paymaster, or paymaster context, you |
| 463 | +can now pass the custom configuration directly to `Web3AuthNoModalOptions` (for non-React) or |
| 464 | +`Web3AuthProvider` options (for React). |
| 465 | + |
| 466 | +**For non-React apps (e.g., VanillaJS, Angular):** |
| 467 | + |
411 | 468 | ```ts |
412 | | -// For non-React apps (e.g., VanillaJS, Angular): |
413 | | -const web3auth = new Web3AuthNoModal({ |
| 469 | +import { WEB3AUTH_NETWORK, Web3AuthNoModalOptions, Web3AuthNoModal } from "@web3auth/no-modal"; |
| 470 | + |
| 471 | +const web3AuthNoModalOptions: Web3AuthNoModalOptions = { |
414 | 472 | clientId: "YOUR_CLIENT_ID", |
415 | | - web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, |
416 | | - accountAbstraction: { |
417 | | - /* Optional: override dashboard settings */ |
| 473 | + web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET, |
| 474 | + // highlight-start |
| 475 | + accountAbstractionConfig: { |
| 476 | + smartAccountType: "metamask", |
| 477 | + chains: [ |
| 478 | + { |
| 479 | + chainId: "0x1", |
| 480 | + bundlerConfig: { |
| 481 | + url: "YOUR_BUNDLER_URL", |
| 482 | + // This is just an example of how you can configure the paymaster context. |
| 483 | + // Please refer to the documentation of the paymaster you are using |
| 484 | + // to understand the required parameters. |
| 485 | + paymasterContext: { |
| 486 | + token: "SUPPORTED_TOKEN_CONTRACT_ADDRESS", |
| 487 | + sponsorshipPolicyId: "sp_my_policy_id", |
| 488 | + }, |
| 489 | + }, |
| 490 | + paymasterConfig: { |
| 491 | + url: "YOUR_PAYMASTER_URL", |
| 492 | + }, |
| 493 | + }, |
| 494 | + ], |
418 | 495 | }, |
419 | | -}); |
| 496 | + // highlight-end |
| 497 | +}; |
420 | 498 |
|
421 | | -// For React apps, pass it to the Web3AuthProvider options: |
422 | | -const web3AuthOptions = { |
| 499 | +// Initialize Web3AuthNoModal with these options |
| 500 | +// const web3auth = new Web3AuthNoModal(web3AuthNoModalOptions); |
| 501 | +// await web3auth.init(); |
| 502 | +// await web3auth.connectTo(...); |
| 503 | +``` |
| 504 | + |
| 505 | +**For React apps:** |
| 506 | + |
| 507 | +```tsx |
| 508 | +import { Web3AuthProvider, WEB3AUTH_NETWORK } from "@web3auth/no-modal/react"; |
| 509 | +// Define Web3AuthProviderOptions if not already defined/imported |
| 510 | +import type { Web3AuthProviderOptions } from "@web3auth/no-modal/react"; |
| 511 | + |
| 512 | +const web3AuthProviderOptions: Web3AuthProviderOptions = { |
423 | 513 | clientId: "YOUR_CLIENT_ID", |
424 | | - web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET, |
425 | | - accountAbstraction: { |
426 | | - /* Optional: override dashboard settings */ |
| 514 | + web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET, |
| 515 | + // highlight-start |
| 516 | + accountAbstractionConfig: { |
| 517 | + smartAccountType: "metamask", |
| 518 | + chains: [ |
| 519 | + { |
| 520 | + chainId: "0x1", |
| 521 | + bundlerConfig: { |
| 522 | + url: "YOUR_BUNDLER_URL", |
| 523 | + // This is just an example of how you can configure the paymaster context. |
| 524 | + // Please refer to the documentation of the paymaster you are using |
| 525 | + // to understand the required parameters. |
| 526 | + paymasterContext: { |
| 527 | + token: "SUPPORTED_TOKEN_CONTRACT_ADDRESS", |
| 528 | + sponsorshipPolicyId: "sp_my_policy_id", |
| 529 | + }, |
| 530 | + }, |
| 531 | + paymasterConfig: { |
| 532 | + url: "YOUR_PAYMASTER_URL", |
| 533 | + }, |
| 534 | + }, |
| 535 | + ], |
427 | 536 | }, |
| 537 | + // highlight-end |
428 | 538 | }; |
| 539 | + |
| 540 | +// In your App or context provider: |
| 541 | +// <Web3AuthProvider options={web3AuthProviderOptions}> |
| 542 | +// <YourApp /> |
| 543 | +// </Web3AuthProvider> |
429 | 544 | ``` |
430 | 545 |
|
431 | | -> ✅ The `@web3auth/account-abstraction-provider` package is deprecated. |
| 546 | +> ✅ **Simplified Setup:** Smart Account configuration is now primarily dashboard-driven, with |
| 547 | +> optional client-side overrides for advanced cases, deprecating the need for the separate |
| 548 | +> `@web3auth/account-abstraction-provider` package. |
432 | 549 |
|
433 | 550 | </TabItem> |
434 | 551 | </Tabs> |
|
0 commit comments