Skip to content

Commit e86f07d

Browse files
recreated example apps content using new prompt
1 parent 756862a commit e86f07d

File tree

31 files changed

+922
-1031
lines changed

31 files changed

+922
-1031
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"features": [
3+
"connect-with-metamask"
4+
]
5+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"title": "Connect with MetaMask in Next.js",
3-
"description": "A Next.js example showing how to connect to MetaMask using the Immutable Checkout SDK with and without permission requests",
4-
"keywords": ["Immutable", "SDK", "Checkout", "MetaMask", "Wallet Connect", "Next.js", "Web3"],
5-
"tech_stack": ["Next.js", "TypeScript", "MetaMask", "Biome UI", "Ethers.js"],
2+
"title": "Connect with MetaMask using the Checkout SDK",
3+
"description": "Learn how to connect a MetaMask wallet to your application using Immutable's Checkout SDK, with options for connecting with or without permissions.",
4+
"keywords": ["Immutable", "SDK", "Checkout", "Wallet", "MetaMask", "Connect", "Next.js"],
5+
"tech_stack": ["Next.js", "TypeScript", "Ethers.js", "Biom3", "React"],
66
"product": "Checkout",
77
"programming_language": "TypeScript"
88
}
Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,119 @@
1-
# Connecting to MetaMask with Checkout SDK in Next.js
1+
# Connect with MetaMask using the Checkout SDK
22

33
## Introduction
4-
This example app demonstrates how to connect your Next.js application to MetaMask using the Immutable Checkout SDK. It showcases how to initialize the SDK, create a provider for MetaMask, and establish a wallet connection with or without requesting permissions.
4+
This example app demonstrates how to connect a MetaMask wallet to your application using Immutable's Checkout SDK. It shows two different connection approaches: connecting with permissions and connecting without permissions. This app serves as a practical guide for implementing wallet connections, a fundamental step in blockchain application development.
55

66
[View app on Github](https://github.com/immutable/ts-immutable-sdk/tree/main/examples/checkout/sdk-connect-with-nextjs)
77

88
## Features Overview
9-
- Get list of supported wallets
10-
- Create a MetaMask provider using Checkout SDK
11-
- Connect to MetaMask with permission requests
12-
- Connect to MetaMask without permission requests
13-
- Validate provider and connection status
14-
- Get connection status
9+
- Connect to MetaMask wallet with wallet permissions
10+
- Connect to MetaMask wallet without wallet permissions
11+
- Retrieve the list of supported wallets
12+
- Check if a provider is valid
13+
- Verify wallet connection status
1514

1615
## SDK Integration Details
1716

18-
### **Get Wallet Allow List**: [Retrieve supported wallets](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#L28-L31)
17+
### Connect with MetaMask
18+
**Feature Name**: Connect a wallet to the application using MetaMask.
19+
20+
**Source Code**: [source code file](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx)
21+
22+
**Implementation**:
23+
24+
1. Getting the list of supported wallets:
1925
```typescript
2026
// Get the list of default supported providers
2127
const type = checkout.WalletFilterTypes.ALL;
2228
const allowListRes = await checkoutSDK.getWalletAllowList({ type });
2329
```
24-
**Explanation**: This code retrieves a list of all wallets supported by the Checkout SDK. The `WalletFilterTypes.ALL` parameter ensures all available wallet providers are returned in the response.
2530

26-
### **Create MetaMask Provider**: [Initialize wallet provider](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#L35-L38)
31+
2. Creating a MetaMask provider:
2732
```typescript
2833
// Create a provider given one of the default wallet provider names
2934
const walletProviderName = checkout.WalletProviderName.METAMASK;
3035
const providerRes = await checkoutSDK.createProvider({ walletProviderName });
3136
```
32-
**Explanation**: This code creates a provider specifically for MetaMask. The SDK handles the interaction with the browser extension and returns a provider object that can be used for subsequent operations.
3337

34-
### **Validate Provider**: [Check provider validity](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#L43-L45)
38+
3. Validating the provider:
3539
```typescript
36-
// Check if the provider if a BrowserProvider
40+
// Check if the provider is a BrowserProvider
3741
const isProviderRes = checkout.Checkout.isWrappedBrowserProvider(providerRes.provider);
3842
```
39-
**Explanation**: This function validates that the provider returned by the SDK is a proper BrowserProvider that can be used for blockchain interactions. This validation is essential before attempting to connect to a network.
4043

41-
### **Connect with Permissions**: [Connect with wallet permissions](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#L50-L55)
44+
4. Connecting to the wallet with permissions:
4245
```typescript
43-
// Get the current network information
44-
// Pass through requestWalletPermissions to request the user's wallet permissions
46+
// Connect with permissions
4547
const connectRes = await checkoutSDK.connect({
4648
provider: providerRes.provider,
4749
requestWalletPermissions: true,
4850
});
4951
```
50-
**Explanation**: This code establishes a connection to the wallet while explicitly requesting permissions from the user. This approach is useful when your application needs specific permissions to interact with the user's wallet.
5152

52-
### **Connect without Permissions**: [Connect without additional permissions](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#L59-L63)
53+
5. Connecting to the wallet without permissions:
5354
```typescript
54-
// Get the current network information
55+
// Connect without permissions
5556
const connectRes = await checkoutSDK.connect({
5657
provider: providerRes.provider
5758
});
5859
```
59-
**Explanation**: This code connects to the wallet without explicitly requesting permissions. This is suitable for applications that only need basic wallet interactions.
6060

61-
### **Check Connection Status**: [Verify connection status](https://github.com/immutable/ts-immutable-sdk/blob/main/examples/checkout/sdk-connect-with-nextjs/src/app/connect-with-metamask/page.tsx#L67-L70)
61+
6. Checking connection status:
6262
```typescript
63-
// Check if the provider if a BrowserProvider
63+
// Check if the provider is connected
6464
const isConnectedRes = await checkoutSDK.checkIsWalletConnected({
6565
provider: providerRes.provider
6666
});
6767
```
68-
**Explanation**: This function verifies if the wallet is connected and returns the connection status along with the wallet address. This is useful for displaying the user's wallet status in the UI.
68+
69+
**Explanation**:
70+
The app first retrieves a list of supported wallet providers using the `getWalletAllowList` method. It then creates a MetaMask provider using the `createProvider` method with the MetaMask wallet provider name.
71+
72+
Before attempting to connect, it validates the provider using `isWrappedBrowserProvider`. The connection to the wallet is made through the `connect` method, which can be called with or without requesting permissions. The difference is that when requesting permissions, the wallet will explicitly prompt the user for permission to interact with their wallet.
73+
74+
Finally, the app verifies if the wallet is connected using the `checkIsWalletConnected` method, which returns the connection status and wallet address.
6975

7076
## Running the App
7177

7278
### Prerequisites
73-
- Node.js 18.x or higher
74-
- PNPM package manager
79+
- Node.js and pnpm installed on your machine
7580
- MetaMask browser extension installed
76-
- [Immutable Hub](https://hub.immutable.com/) account for obtaining a publishable API key
81+
- [Set up your environment variables in Immutable Hub](https://hub.immutable.com)
82+
83+
### Steps to Run Locally
7784

78-
### Setup Instructions
7985
1. Clone the repository:
80-
```bash
81-
git clone https://github.com/immutable/ts-immutable-sdk.git
82-
cd ts-immutable-sdk/examples/checkout/sdk-connect-with-nextjs
83-
```
86+
```bash
87+
git clone https://github.com/immutable/ts-immutable-sdk.git
88+
cd ts-immutable-sdk
89+
```
8490

8591
2. Install dependencies:
86-
```bash
87-
pnpm install
88-
```
92+
```bash
93+
pnpm install
94+
```
95+
96+
3. Navigate to the example app:
97+
```bash
98+
cd examples/checkout/sdk-connect-with-nextjs
99+
```
89100

90-
3. Create environment file:
91-
```bash
92-
cp .env.example .env
93-
```
101+
4. Create your environment file:
102+
```bash
103+
cp .env.example .env
104+
```
94105

95-
4. Add your Immutable Hub publishable key to the `.env` file:
96-
```
97-
NEXT_PUBLIC_PUBLISHABLE_KEY=your_publishable_key_here
98-
```
106+
5. Edit the `.env` file and add your publishable API key from Immutable Hub:
107+
```
108+
NEXT_PUBLIC_PUBLISHABLE_KEY=your-publishable-key
109+
```
99110

100-
5. Run the development server:
101-
```bash
102-
pnpm dev
103-
```
111+
6. Start the development server:
112+
```bash
113+
pnpm dev
114+
```
104115

105-
6. Open [http://localhost:3000](http://localhost:3000) in your browser to view the app.
116+
7. Open your browser and navigate to http://localhost:3000 to see the application.
106117

107118
## Summary
108-
This example demonstrates how to integrate Immutable's Checkout SDK with a Next.js application to connect to MetaMask. The app showcases different connection methods (with and without permissions), provider validation, and retrieving wallet information. It provides a foundation for building more complex blockchain applications that require wallet connectivity.
109-
110-
Key takeaways:
111-
- The Checkout SDK simplifies wallet connection in Next.js applications
112-
- You can choose different connection approaches based on your permission requirements
113-
- The SDK provides helpful utilities for validating connections and retrieving wallet information
114-
- The integration works seamlessly with React's state management for displaying connection status
119+
This example demonstrates how to implement wallet connection functionality using Immutable's Checkout SDK. By following this guide, developers can easily integrate MetaMask wallet connectivity into their applications, with options for requesting different permission levels. The app showcases a straightforward implementation that can be extended to build more complex blockchain applications.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"features": [
3+
"gas-estimation-with-metamask"
4+
]
5+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"title": "Gas Estimation with Next.js",
3-
"description": "A Next.js application demonstrating how to use the Immutable Checkout SDK to estimate gas fees for swap and bridge-to-L2 transactions",
4-
"keywords": ["Immutable", "SDK", "Gas Estimation", "MetaMask", "Checkout", "Next.js", "Swap", "Bridge"],
5-
"tech_stack": ["Next.js", "React", "TypeScript", "ethers.js", "Biom3 Design System"],
3+
"description": "A Next.js application demonstrating how to use the Immutable Checkout SDK to estimate gas fees for swap and bridge to L2 transactions on Immutable zkEVM",
4+
"keywords": ["Immutable", "SDK", "Gas Estimation", "MetaMask", "Checkout", "Swap", "Bridge", "zkEVM"],
5+
"tech_stack": ["Next.js", "React", "TypeScript", "MetaMask", "Biom3"],
66
"product": "Checkout",
77
"programming_language": "TypeScript"
88
}

0 commit comments

Comments
 (0)