This project demonstrates onchain randomization using both Chainlink VRF and Pyth Entropy for a provably fair coin flip game. It includes smart contracts, deployment scripts, and tests for both randomness providers.
- Chainlink VRF Coin Flip: See
contracts/withVRF.sol
- Pyth Entropy Coin Flip: See
contracts/withEntropy.sol
- Mock ERC20 token for testing:
contracts/mocks/MockToken.sol
- Hardhat-based development environment
- Example deployment scripts for both randomness providers:
contracts/ # Solidity smart contracts
scripts/ # Deployment scripts
test/ # Test files
abi/ # Exported ABIs
artifacts/, cache/ # Hardhat build artifacts
ignition/ # Hardhat Ignition deployment modules
types/ # Typechain generated types
npm install
Copy .env.example
to .env
and fill in your keys:
cp .env.example .env
key
: Your deployer private keybasescankey
: BaseScan API key for contract verificationCOINMARKETCAP_API_KEY
: For gas reporter (optional)
npm run build
npx hardhat test
-
Chainlink VRF Coin Flip:
npx ts-node scripts/deploy/vrf.deploy.ts
-
Pyth Entropy Coin Flip:
npx ts-node scripts/deploy/entropy.deploy.ts
- For Chainlink VRF, create and fund a subscription at vrf.chain.link.
- For Pyth Entropy, see Pyth Entropy contract addresses and fee info.
- Update contract addresses and subscription IDs in the deployment scripts as needed.
MIT
Switching from Chainlink VRF to Pyth Entropy
This repo provides a reference for integrating both randomness solutions in onchain games.