This example React app renders a minting pre-sale/public-sale widget for an NFT collection.
flair-sdk: latestreact: v17.x or v18.x
-
Create a new NFT collection using Flair's dashboard. Note that you will be the full owner of smart contract.
-
Clone the examples repo, install dependencies in the
custom-nft-minting-salesdirectory:git clone https://github.com/0xflair/examples cd examples/react/custom-nft-minting-sales npm install -
Grab your contract address and chain ID, and update .env:
- Set
REACT_APP_COLLECTION_CONTRACT_ADDRESSto your deployed contract address you get from Flair's dashboard > Collections > your-collection > Deploy tab. - Set
REACT_APP_COLLECTION_CHAIN_IDdepending on the contract chain. Use1for Eth mainnet,4for Rinkeby testnet,137for Polygon mainnet, etc.
- Set
-
Run the react app in the
custom-nft-minting-salesdirectory:npm start
-
Open http://localhost:3000 to view it in the browser.
To use this example within your app:
-
Install
flair-sdkin your React app:npm install flair-sdk
-
Configure FlairProvider around your root App:
import { FlairProvider } from 'flair-sdk'; // ... <FlairProvider> <App /> </FlairProvider> // ...
-
Implement the minting widget depending on your preferred customizability:
- Easiest approach with minimum customizability you can copy the code within App.tsx.
- To have your own layout you can use individual components as in CollectionSalesMintingSection.tsx
-
(optional) To get the default styling you can install and configure tailwindcss:
- Install
npm install tailwindcss @headlessui/react @heroicons/react - Configure tailwind.config.js
- Configure postcss.config.js
- Import tailwind in your index.css. Make sure your app imports the CSS
import './index.css';.
- Install
-
(optional) If you're using Webpack 5 (e.g. React v17+) you need to manually configure Buffer for Coinbase wallet to work:
- Install
npm install react-app-rewired buffer - Then create a config-overrides.js to inject the Buffer.
- Install
-
Profit 🚀
