Skip to main content
Use this guide when you need on-chain verifiable randomness or provably fair NFT minting on Berachain. Pyth Entropy lets you request secure random numbers and use them in smart contract callbacks (e.g. mint an NFT with a random trait).

Repository

Official documentation

Requirements

  • Node v20.11.0 or greater, npm
  • Wallet with Berachain testnet $BERA — Artio Faucet
  • Foundry (foundryup)

Stack

Solidity, Foundry (Forge), Node.js, @pythnetwork/entropy-sdk-solidity, OpenZeppelin contracts.

Quick start

  1. Clone and install
    git clone https://github.com/berachain/guides.git && cd guides/apps/pyth-entropy
    npm install
    
    Add remappings to foundry.toml (see README).
  2. Configure .env at project root: RPC_URL, PRIVATE_KEY, ENTROPY_ADDRESS, PROVIDER_ADDRESS (values in README).
  3. Deploy the NFT contract
    forge create src/EntropyNFT.sol:EntropyNFT --private-key $PRIVATE_KEY --rpc-url $RPC_URL --constructor-args $ENTROPY_ADDRESS $PROVIDER_ADDRESS
    
    Set ENTROPY_NFT_ADDRESS in .env to the deployed address.
  4. Request a mint (script requests random number from Pyth and polls for the mint callback)
    node app/requestMint.js
    

Key files

PurposePath
NFT contractsrc/EntropyNFT.sol
Mint request scriptapp/requestMint.js