This repository demonstrates how to leverage Pyth's Entropy service to enable provably fair NFT minting on the Berachain network. By utilizing Entropy, developers can generate secure random numbers on-chain, ensuring the fairness of an NFT minting process.
👉 Learn more about Pyth Entropy
- Node
v20.11.0or greater - npm
- Wallet with Berachain Testnet $BERA tokens - See the Berachain Artio Faucet
- Foundry - ensure
foundryupis run to install binaries
Install project dependencies:
# FROM: ./pyth-entropy
npm install;Run the following to add remappings to foundry.toml:
# FROM: ./pyth-entropy
echo "remappings = ['@pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity', '@openzeppelin/contracts/=node_modules/@openzeppelin/contracts']" >> ./foundry.tomlCreate a .env file at the project root and populate it with the following:
RPC_URL=https://artio.rpc.berachain.com/
ENTROPY_NFT_ADDRESS=YOUR_ENTROPY_NFT_ADDRESS
PRIVATE_KEY=YOUR_PRIVATE_KEY
ENTROPY_ADDRESS=0x26DD80569a8B23768A1d80869Ed7339e07595E85
PROVIDER_ADDRESS=0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344Replace YOUR_PRIVATE_KEY with your wallet's private key.
Load these environment variables into your terminal session:
# FROM: ./pyth-entropy
source .env;Now deploy the EntropyNFT contract to the Berachain Testnet:
# FROM: ./pyth-entropy
forge create src/EntropyNFT.sol:EntropyNFT \
--private-key $PRIVATE_KEY \
--rpc-url $RPC_URL \
--constructor-args $ENTROPY_ADDRESS $PROVIDER_ADDRESS \Update the ENTROPY_NFT_ADDRESS in the .env file with your deployed contract address.
Run the app/requestMint.js script to:
- Request a random number from Pyth; and
- Poll the NFT contract events for when Pyth executes the minting callback (expected to happen in a few blocks)
# FROM: ./pyth-entropy
node app/requestMint.js;
# [Example Output]:
# ✅ NFT ID 303 minted to 0xf290f3d843826d00f8176182fd76550535f6dbb4, based on sequenceNumber 114You will now have minted a randomized NFT from your new collection!
