Part 1 - Connect Wallet using Metamask and mint an NFT
This 2-part tutorial will guide you through integrating with Bastion SDK in your Next.js app through Metamask and then using social login via Particle Auth.
This is Part 1 of the tutorial.
Prerequisites
Node.js and npm installed
Basic understanding of Next.js and React
A Bastion account for API key
A Particle Network account
Step 1: Set Up Your Next.js Project
If you haven't already set up a Next.js project, create one by running:
npx create-next-app nextjs-demo-appMake sure that you choose the following options for this demo to work. (It should still work with different options, but the project structure would be different).

Note:- If you're using App Router in NextJS 13, you should use /app/index.tsx instead of /pages/index.tsx
Navigate into your project folder:
Step 2: Install Required Packages
Install the required npm packages:
Step 3: Get Bastion API Key
Log in to the Bastion Dashboard.
Generate a new API key.
Step 4: Add Environment Variables
Create a .env.local file at the root of your Next.js project and add the following:
Replace the placeholder values with your Bastion API key.
Step 5: Implement connect with Metamask and connect with Bastion
Add the following code to the file pages/index.tsx
Step 6: Add CSS
Go to your globals.css file, which is usually under /styles.
Add the following CSS at the bottom -
Step 7: Test your app
Now you can run your app using
Navigate to http://localhost:3000 and click on the "Login with Metamask" button. Follow the usual Metamask login procedure, and you should see your Ethereum address displayed on the screen, indicating a successful login.

You should also see a Mint NFT button on the page now. If you click on this button, the app will mint an NFT to your Smart Wallet by sending a User Operation on the Arbitrum Goerli testnet using the Pimlico bundler.

That's it! You've successfully integrated Metamask with the Bastion SDK in a Next.js application. You can now proceed to build more complex functionalities into your decentralized application.
Last updated