Impact-Finance / intheory-mobile-nft-mint-celo

Mobile application for minting AI-generated pre-launch NFTs for the inTheory platform. Built during Celo Camp.

Home Page:intheory-mobile-nft-mint-celo.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

inTheory Pre-Launch NFT Minting App

GitHub license GitHub forks Twitter

Hosted app can be found at intheory.impact-finance.io

Questions about this repo? Contact us at info@impact-finance.io

Project description

This application allows users to select the scientific research topics that are of greatest interest to them and then uses that selection to create an AI-generated artwork that can be minted as an NFT on the Celo blockchain. Doing so creates a permanent record and verifier of their research interests and their support for open science. The selection of topics by the community will be used to influence the first wave of projects funded by the inTheory DeSci platform when it launches.

This application could be repurposed by any early-stage web3 project that wants to create an engaging and verifiable way to poll community interest, without requiring a governance token. Also notice that this repo does not require smart contract dev skills or any knowledge of Solidity to operate, as it uses Tatum for all blockchain interactions.

Why did we build this?

We built this application to activate engagement from our early supporters and to provide a verifiable means for them to influence platform development prior to the launch of our governance token. It allows users to collect a piece of personalized digital artwork inspired by their selections, while giving us a clear gauge on community interest. This application also provides a mechanism for distributing rewards to our earliest supporters.

This application was built as part of our participation in Celo Camp Batch 6.

Where can you learn more?

inTheory: Website | Twitter | LinkedIn | Medium

DeSci: ethereum.org/en/desci/

Celo: Celo Blockchain

How to install and run

Installation

# install dependencies
yarn install

# install Netlify CLI
npm install netlify-cli -g

# run with Netlify
netlify dev

How does it work

This application is a Next.js app.

Netlify

This application is hosted on Netlify and uses Netlify functions to execute server-side code. These functions can be found in the /netlify/functions directory and can be moved to accommodate hosting on other services. Note that these functions often involve API calls requiring an API key and for security purposes, they should not be run from the client side. More information on Netlify's functions can be found in their docs.

Note that the default timeout for Netlify functions is 10 seconds, which is likely too short for the Stable Diffusion API call. This default timeout can be extended by contacting Netlify support. You will then want to link your local repo to your Netlify app for testing during development by running netlify link --name [my-site-name]. More info here.

Stable Diffusion

This application uses the Stable Diffusion model for creating AI-generated artworks. This API call can be found in /netlify/functions/stability-call.js. The API call sends a text prompt that includes the selected research topics, as well as some randomly generated stylistic elements from /utils/randDescriptor.js through Replicate's AI service.

This repo also includes a function in /netlify/functions/dream-call.js for utilizing WOMBO's Dream API if that is preferred, though some additional configuration would be needed to correctly receive the image response. More information here.

AWS S3

After the AI art generation is completed, all images are uploaded to an AWS S3 bucket for internal record keeping. Since the image is then immediately streamed to IPFS for creation of metadata, the S3 storage step could be skipped if desired.

Celo

This application was built to be used on the Celo blockchain and uses react-celo to connect user wallets. Celo is an EVM compatible chain, and so this hook could be easily replaced with a wallet connection function of your choice (such as RainbowKit or Dynamic) for launching on other EVM chains.

Also note that this app could easily be adapted to not require users to connect their wallets at all. Since blockchain interactions are handled through Tatum, it is possible to mint an NFT to a user by just collecting their wallet address through a React form and submitting the address to the Tatum API. We chose not to do this, as we wanted to verify our users' ownership over their wallets.

For testing, the following config should be added in _app.js to make the Celo Alfajores Testnet the default network.

import { CeloProvider, NetworkNames } from '@celo/react-celo';
import '@celo/react-celo/lib/styles.css';

<CeloProvider
    ...
    defaultNetwork={NetworkNames.Alfajores}
    >
    <App />
</CeloProvider>

Pinata

We use Pinata for pinning images and NFT metadata to IPFS. The API call to do so can be found in /netlify/functions/ipfs-stream.js. This function contains the NFT metadata schema that should be adjusted for your specific use case.

Our Pinata dedicated gateway is also used in /components/Done.js for displaying NFT metadata. Our dedicated gateway will only serve files pinned to our Pinata account, and so the URL will need to be reconfigured to function for your application.

The process of minting the NFTs takes 5 minutes due to the latency inherent to interactions with IPFS. Without a waiting period after metadata upload, the process of attaching metadata to the token may fail.

Tatum

We use the Tatum API for all communication with the blockchain. This allows us to avoid using Solidity to deploy our own smart contracts and allows us to pay gas fees for minting NFTs, providing a better user experience.

The Tatum API calls that we utilize are:

-Deploy an NFT Smart Contract (not done in app, performed only once to create NFT minting contract)

-Add an NFT Minter (not done in app, performed only once to allow Tatum to mint NFTs using our contract)

-Get NFTs from a Collection (done in app to query number of NFTs minted to date, which helps us set token ID - more info below)

-Get the NFTs from a Specific Smart Contract that a Blockchain Address Holds (done to verify that only one NFT is being minted per blockchain address)

-Minting NFTs with NFT Express Using your own Smart Contract (done to mint NFTs using our deployed smart contract)

Note on token IDs: To increase early demand, we elected to have the first 50 NFTs minted to our collection have a tokenID ranging from 1-50. After the 50th NFT has been minted, all future NFTs will have an arbitrary tokenID (generated by Date.now()). This provides a simple mechanism to mark the earliest NFTs minted in the collection and increase their value above the others.

Environment variables

The environment variables required for this application are below.

DREAM_API_KEY    //only required if using Dream for image gen
REPLICATION_STABILITY_API_KEY   //only required if using Stable Diffusion for image gen
PINATA_JWT
s3AccessKeyId
s3AccessSecret
s3Region
s3Bucket
TATUM_API_KEY
contractAddress   //contract address of your ERC-721 NFT smart contract

License

This source code is licensed under the Apache-2.0 license found in the LICENSE file in the root directory of this source tree.

About

Mobile application for minting AI-generated pre-launch NFTs for the inTheory platform. Built during Celo Camp.

intheory-mobile-nft-mint-celo.vercel.app

License:Apache License 2.0


Languages

Language:JavaScript 86.9%Language:CSS 13.1%