What you will be building, see our git repo for the finished work and our live demo.
Welcome to our comprehensive guide on "Building a Web3 Events Marketplace with Next.js, TypeScript, and Solidity". In this tutorial, we'll construct a decentralized Events Marketplace that harnesses the power of blockchain technology. You'll gain a clear understanding of the following:
By the end of this guide, you'll have a functioning decentralized platform where users can list and participate in events, with all transactions managed and secured by Ethereum smart contracts.
As an added incentive for participating in this tutorial, we're giving away a copy of our prestigious book on becoming an in-demand Solidity developer. This offer is free for the first 300 participants. For instructions on how to claim your copy, please watch the short video below.
You will need the following tools installed to build along with me:
To set up MetaMask for this tutorial, please watch the instructional video below:
Once you have successfully completed the setup, you are eligible to receive a free copy of our book. To claim your book, please fill out the form to submit your proof-of-work.
Watch the following instructional videos to receive up to 3-months of free premium courses on Dapp Mentors Academy, including:
Join the Bitfinity ecosystem and be a part of the next generation of dApps. Apply your Bitfinity knowledge to create a Blockchain-based House Rental dApp in the final module. Deploy your smart contracts to the Bitfinity network and revolutionize the rental industry
With that said, let’s jump into the tutorial and set up our project.
We'll start by cloning a prepared frontend repository and setting up the environment variables. Run the following commands:
git clone https://github.com/Daltonic/dappEventX
cd dappEventX
yarn install
git checkout 01_no_redux
Next, create a .env
file at the root of the project and include the following keys:
NEXT_PUBLIC_RPC_URL=http://127.0.0.1:8545
NEXT_PUBLIC_ALCHEMY_ID=<YOUR_ALCHEMY_PROJECT_ID>
NEXT_PUBLIC_PROJECT_ID=<WALLET_CONNECT_PROJECT_ID>
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=somereallysecretsecret
Replace <YOUR_ALCHEMY_PROJECT_ID>
and <WALLET_CONNECT_PROJECT_ID>
with your respective project IDs.
YOUR_ALCHEMY_PROJECT_ID
: Get Key Here
WALLET_CONNECT_PROJECT_ID
: Get Key Here
Finally, run yarn dev
to start the project.
Our user interface is prepared to incorporate smart contracts, however, we still need to integrate Redux in order to facilitate the sharing of data.
The above image represents the structure of our Redux store, it will be simple since we are not creating some overly complex project.
We'll set up Redux to manage our application's global state. Follow these steps:
store
folder at the project root.store
, create two folders: actions
and states
.states
, create a globalStates.ts
file.actions
, create a globalActions.ts
file.globalSlices.ts
file inside the store
folder.index.ts
file inside the store
folder.pages/_app.tsx
file with the Redux provider.We have implemented Redux toolkit in our application and plan to revisit its usage when integrating the backend with the frontend.
Next, we'll develop the smart contract for our platform:
contracts
folder at the project root.contracts
, create a DappEventX.sol
file and add the contract code below.The above smart contract is designed to manage an Events Marketplace on the blockchain. It allows users to create, update, and delete events, buy tickets for events, and handle payouts. Here's a detailed breakdown of its functions:
constructor(uint256 _pct) ERC721('Event X', 'EVX')
): This function initializes the contract, sets the service fee percentage, and assigns initial token parameters.Now, let's deploy our smart contract and populate it with some dummy data:
scripts
folder at the project root.scripts
, create a deploy.js
and a seed.js
file and add the following codes.
Deploy Script
Seed
Run the following commands to deploy the contract and seed it with data:
yarn hardhat node # Run in terminal 1 yarn hardhat run scripts/deploy.js # Run in terminal 2 yarn hardhat run scripts/seed.js # Run in terminal 2
If you did that correctly, you should see a similar output like the one below:
At this point we can start the integration of our smart contract to our frontend.
First, create a services
folder at the project root, and inside it, create a blockchain.tsx
file. This file will contain functions to interact with our smart contract.
The above code is a service that interacts with a Events Marketplace contract. The service interacts with a smart contract deployed on the Ethereum blockchain using the ethers.js library.
Here's a detailed breakdown of its functions:
Next, update the provider.tsx
file inside services
to include the bitfinity
network using the following codes.
Next, we'll link the functions in the blockchain service to their respective interfaces in the frontend:
No 1: Displaying Available Events
Update pages/index.tsx
to get data from the getEvents()
function.
Take a moment and observe how we implemented the load more button, I bet you’ll find it useful.
No 2: Displaying User’s Events
Update pages/events/personal.tsx
to get data from the getMyEvents()
function.
No 3: Creating New Event
Update pages/events/create.tsx
to use the createEvent()
function for form submission..
No 4: Displaying Single Event
Update pages/events/[id].tsx
to get data from the getEvent()
and getTickets()
functions.
No 5: Editing a Single Event
Change pages/events/edit/[id].tsx
to retrieve data from the getEvent()
and update by calling updateEvent()
.
No 6: Displaying Event Tickets
Update pages/events/tickets/[id].tsx
to retrieve data from the getTickets()
function.
Let's apply the same approach we used for the previous pages and update the following components to interact with the smart contract.
No 1: Purchasing Ticket
Update components/BuyTicket.tsx
file to use the handleSubmit()
function to call the buyTicket()
function.
No 2: Deleting and Paying out Events
Lastly, update components/EventAction.tsx
file to use the deleteEvent()
and payout()
functions.
It should be noted that this component is a dropdown and contains the relevant actions for managing a specific event.
All the components and pages of the project have been successfully connected to the smart contract, indicating the completion of the project after implementing these updates.
If your Next.js server was offline, you can bring it back up by executing the command yarn dev
.
For further learning, we recommends subscribing to our YouTube channel and visiting our website for additional resources.
In this tutorial, we have successfully built a Web3 Events Marketplace using Next.js, TypeScript, and Solidity. We've established the development environment, constructed the Redux store, and deployed our smart contract to our local chain.
We've created dynamic interfaces, crafted Ethereum smart contracts, and managed shared data with Redux. By integrating the smart contract with the frontend, we've enabled users to list and participate in events, with transactions managed and secured by Ethereum smart contracts.
Now, you're equipped with the skills to build your own Web3 Events Marketplace. We've also provided you with a live demo and the finished work in our git repo for reference. Happy coding!
I am a web3 developer and the founder of Dapp Mentors, a company that helps businesses and individuals build and launch decentralized applications. I have over 7 years of experience in the software industry, and I am passionate about using blockchain technology to create new and innovative applications. I run a YouTube channel called Dapp Mentors where I share tutorials and tips on web3 development, and I regularly post articles online about the latest trends in the blockchain space.
Stay connected with us, join communities on Discord: Join X-Twitter: Follow LinkedIn: Connect GitHub: Explore Website: Visit