Web3Auth Examples
repository·main·Indexed 40 days ago
https://github.com/web3auth/web3auth-examplesA collection of ready-to-run examples for MetaMask Embedded Wallets powered by Web3Auth. This repository demonstrates how to integrate non-custodial social login wallets across various frontend frameworks, authentication providers (such as Auth0, Google OAuth, Firebase, and GitHub), and blockchain networks, including implementations of grouped connections to ensure identity consistency across different login methods.
What's inside Web3Auth
- This example demonstrates how to use MetaMask Embedded Wallets (powered by Web3Auth) as a signer for EVM transactions using Wagmi in a React + Vite environment. The workflow involves performing a social login to derive a wallet via Web3Auth, then using standard Wagmi hooks to send transactions through that derived wallet.
Project structure of the React Solana Quick Start
mainThe project is organized as follows:
src/solana/transfer.ts: Contains the Solana Kit logic to build SOL transfer transactions.src/components/: Contains individual React components demonstrating specific Web3Auth Solana hooks.src/web3authContext.tsx: Web3Auth context configuration.src/main.tsx: The entry point whereWeb3AuthProviderandSolanaProviderwrap the application.
What is a grouped connection in MetaMask Embedded Wallets?
mainA grouped connection is a feature that links multiple authentication providers to a single identity.
Why use it? Without grouping, if a user signs in with Google and later signs in with Auth0 (e.g., via GitHub), they would be issued two completely different wallet addresses. By using a grouped connection, MetaMask Embedded Wallets ensures that the same user always gets the same wallet address regardless of which configured provider they use to sign in.
Configure Custom Authentication: Single vs Grouped Connections
mainMetaMask Embedded Wallets supports two primary patterns for custom authentication providers:
Single Connection
Each example wires one external identity provider to a dedicated Web3Auth connection. This is used when one provider maps to one wallet.
- OAuth/Implicit Flows: Google, Facebook, Discord, Twitch, Worldcoin.
- JWT Flows: Auth0 (JWT), Firebase (JWT), Custom JWT.
- Other: AWS Cognito (Implicit), Modal (Modal).
Grouped Connections
Grouped connections allow multiple login methods (e.g., Social Login + Email Passwordless) to resolve to the same wallet address for a single user. This is essential for user retention and account recovery.
- Examples: Auth0 + Google (Implicit/JWT), Firebase + Google (JWT), Google + Email Passwordless (Modal).
Important: You must set up your connection on the Web3Auth Dashboard before running these examples.
Understand Grouped Connections in MetaMask Embedded Wallets
mainA grouped connection allows you to combine multiple authentication methods (such as Google OAuth and email passwordless) so that a user always receives the same wallet address regardless of which method they use to sign in.
Without grouping, a user signing in with Google and later with email passwordless would be assigned two separate, disconnected wallets. Grouping ensures identity consistency across different login providers.
Understand the division of responsibilities between Web3Auth and Solana Kit
mainIn this integration, responsibilities are split between the Web3Auth SDK and the Solana Kit. Web3Auth handles the identity and blockchain interaction layer, while Solana Kit is used strictly for transaction construction.
Web3Auth (
@web3auth/modal/vue/solana) Responsibilities:- Authentication: Login and logout via
useWeb3AuthConnectanduseWeb3AuthDisconnect. - Wallet State: Accessing the wallet address via
useSolanaWallet→accounts. - Blockchain Interaction: Reading from the chain or using RPC via
useSolanaWallet→rpc. - Signing: Signing messages with
useSignMessageand signing transactions withuseSignTransaction. - Transaction Execution: Sending transactions via
useSignAndSendTransaction. - Chain Management: Switching chains using
useSwitchChainanduseWeb3Auth.
Solana Kit (
src/solana/) Responsibilities:- Transaction Building: Constructing specific transaction types, such as SOL transfers using
buildSolTransferTransaction.
Key Concept: The Solana Kit is only used to build the transaction object. The actual signing and the RPC endpoints used for broadcasting are provided by Web3Auth.
- Authentication: Login and logout via
What are Grouped Connections in MetaMask Embedded Wallets
mainA grouped connection combines multiple authentication providers (e.g., Auth0, Google OAuth, and GitHub) so that a single user always receives the same wallet address regardless of which provider they use to sign in.
Without grouping, using different providers (like Google vs. Auth0) for the same person would result in two completely different wallet addresses. This ensures identity consistency across different login methods.
Use Web3Auth provider RPC methods for XRPL
mainIn this XRPL implementation, once the social login is successful, the application interacts with the XRP Ledger by calling Web3Auth provider RPC methods. These methods allow the app to sign transactions and query account information directly through the embedded wallet provider.
Key methods mentioned include:
xrpl_getAccounts: Used to retrieve account information on the XRPL.- Transaction signing and submission: Handled via the provider's RPC interface.
Quick Start: MetaMask Embedded Wallets with Vue and Solana
mainThis boilerplate provides a Vue 3 + Vite implementation of MetaMask Embedded Wallets (Web3Auth) integrated with Solana Kit. It demonstrates how to handle authentication, wallet management, and transaction building for the Solana blockchain.
Prerequisites
- Node.js: 22.12+
- npm
- Web3Auth Client ID: Obtain this from the Web3Auth Dashboard. Ensure you have added Solana chain(s) under Chains & Networks. Note that RPC URLs are managed via the dashboard and are not hardcoded in this example.
Setup Instructions
Clone the repository:
git clone https://github.com/Web3Auth/web3auth-examples.git cd web3auth-examples/quick-starts/vue-solana-quick-startInstall dependencies:
npm installConfigure environment variables: Copy the example env file and set your Client ID:
cp .env.example .envIn the
.envfile, update:VITE_WEB3AUTH_CLIENT_ID=YOUR_CLIENT_IDRun the application:
npm run devThe application will be available at
http://localhost:8080.
Note: Use Sapphire Devnet for local development. Sapphire Mainnet does not support
localhostconnections.git clone https://github.com/Web3Auth/web3auth-examples.git cd web3auth-examples/quick-starts/vue-solana-quick-start npm install cp .env.example .env npm run devQuick Start: React + Solana with MetaMask Embedded Wallets
mainThis boilerplate provides a React + Vite implementation of MetaMask Embedded Wallets (Web3Auth) integrated with Solana Kit. It demonstrates how to handle authentication, wallet address retrieval, and transaction signing/sending on the Solana blockchain.
Core Responsibilities
Feature Web3Auth ( @web3auth/modal/react/solana)Solana Kit ( src/solana/)Login / logout useWeb3authConnect,useWeb3authDisconnect— Wallet address useSolanaWallet→accounts— Read chain / RPC useSolanaWallet→rpc— Sign message useSignMessage— Sign transaction useSignTransactionbuildSolTransferTransactionSend transaction useSignAndSendTransactionbuildSolTransferTransactionSwitch chain useSwitchChain+useWeb3auth— Solana React context SolanaProvider(wraps app)— Note: The Solana Kit is used exclusively to build transfer transactions and format lamports. All signing and RPC interactions are managed by Web3Auth.
Quick Start: MetaMask Embedded Wallets with React
mainThis project provides a minimal React + Vite example demonstrating MetaMask Embedded Wallets (powered by Web3Auth). It utilizes the@web3auth/modalReact SDK, which includes built-in hooks and native Wagmi integration, to provide a pre-built modal UI on EVM chains.Setup the MetaMask Embedded Wallets Solana Name Service (SNS) example
mainThis example demonstrates a React + Vite application using MetaMask Embedded Wallets (powered by Web3Auth) to interact with the Solana Name Service (SNS). Users can perform social logins to resolve
.soldomain names and look up wallet addresses by name.Prerequisites
- Node.js 22.12+
- npm
- A Client ID from the Web3Auth Dashboard configured with the Solana chain.
Installation Steps
- Clone the repository and navigate to the example directory:
git clone https://github.com/Web3Auth/web3auth-examples.git cd web3auth-examples/other/sns-example - Install dependencies:
npm install - Configure environment variables:
Copy the example environment file:
Edit thecp .env.example .env.envfile and set your Client ID:VITE_WEB3AUTH_CLIENT_ID=YOUR_CLIENT_ID
4. **Run the application:** ```bash npm run devThe application will be available at
http://localhost:5173.git clone https://github.com/Web3Auth/web3auth-examples.git cd web3auth-examples/other/sns-example npm install cp .env.example .env # Edit .env with VITE_WEB3AUTH_CLIENT_ID npm run dev