Access control for DApps.
Gatekeeper provides token-based access control for web3 applications. This is enabled by rules defined in a smart-contract. This example uses an ERC721 token with a single boolean state property providing proof of access rights.
Gatekeeper was developed during BlockathonDAO March 2022.
- Ethereum blockchain
- Node (v16 recommended)
- Typescript
- Ethers.js
- Hardhat
- OpenZeppelin
- React
- TailwindCSS
Install node packages:
yarn install
Create a .env
file in root of the repo with the following entries:
ALCHEMY_RINKEBY_URL=https://eth-rinkeby.alchemyapi.io/v2/<YOUR_API_KEY>
PRIVATE_KEY=...
COINMARKETCAP_API_KEY=...
Compile the contract:
yarn sol:compile
Start the application:
yarn run dev
To run the tests for the contract functions:
yarn run sol:test
If you prefer to use your own instance of the SleepyKoala contract:
yarn sol:compile
yarn sol:deploy:rinkeby
- Update
contractAddress
in Minter.tsx with the contract address returned in step 2. - Restart the application.
The sample contract is deployed on the Rinkeby testnet. You will require a small amount of test ETH.
- On the home page connect to your MetaMask wallet.
- Click the Mint KOL button.
- Confirm the transaction in the MetaMask wallet and wait for the minted NFT.
- The new NFT does not have sufficient access privileges so click the Invert NFT button.
- Confirm the transaction and wait for access to be granted.
Note: For ease of demonstration and testing the app requires a new token to be minted every time. In a real-world scenario the newly minted KOL token will be automatically detected in the users wallet.
mint()
getTokenData()
invertTokenData()
setTokenData()