Skip to content

thirdweb-example/community-rewards

Repository files navigation

Important

This repository is referencing the mumbai chain.

Mumbai is deprecated since 08/04/2024, meaning the code in this repository will no longer work out of the box.

You can still use this repository, however you will have to switch any references to mumbai to another chain.

Community Rewards

Introduction

This example utilizes signature-based minting of NFTs as a mechanism to reward users of a specific community. We connect user's with their Discord account, and generate signatures for an NFT if the user is a member of the Discord server.

Using This Template

Create a project using this example:

npx thirdweb create --template
community-rewards
  • Create an NFT Collection contract using the dashboard.
  • Update the contract address and discord server id in the consts file.

Setting up Discord OAuth

Head to the Discord Developer portal and create a new application.

Under the Oauth2 tab, copy your client ID and client secret. We need to store these as environment variables in our project so that we can use them on the API routes in our application.

Create a file at the root of your project called .env.local and add the following lines:

CLIENT_ID=<your-discord-client-id-here>
CLIENT_SECRET=<your-discord-client-secret-here>

Back in the Discord portal, under the Redirects section, you need to add the following value as a redirect URI:

http://localhost:3000/api/auth/callback/discord

You need to have an environment variable called NEXTAUTH_SECRET for the Discord Oauth to work.

You can learn more about it here: https://next-auth.js.org/configuration/options

You can quickly create a good value on the command line via this openssl command.

openssl rand -base64 32

And add it as an environment variable in your .env.local file:

NEXTAUTH_SECRET=<your-value-here>

Other Environment Variables

To run this project, you will need to add the following environment variables to your .env.local file:

WALLET_PRIVATE_KEY= NEXT_PUBLIC_TEMPLATE_CLIENT_ID= TW_SECRET_KEY=

  • Generate your TW_SECRET_KEY and NEXT_PUBLIC_TEMPLATE_CLIENT_ID via thirdweb's dashboard.
  • For WALLET_PRIVATE_KEY export your wallet private key from your wallet.

Run Locally

Install dependencies

  # npm
  npm install

  # yarn
  yarn install

Start the server

  # npm
  npm run start

  # yarn
  yarn start

Additional Resources

Contributing

Contributions and feedback are always welcome! Please check our open source page for more information.

Need help?

For help, join the discord or visit our support page.