This is the smart contract code for the reallucky.io project, which ensures a 100% match with the deployed contract online, with no modification. At the same time, the source code of the contract has also been source code verified on bscscan.com.
Binance Smart Chain
0xbbb1381e648c66ca10d2bb1ccea46993eef556c8
- Install Node.js, recommended version 18 or above
- Use npm or yarn package manager
npm install -D
DEPLOYER_PK='Your deployment account private key, without 0x'
GOV_PK='Your governance account private key, without 0x'
#There are a total of 10 test accounts, please complete them yourself
TEST_1_PK='Your test account 1 private key, without 0x'
...
TEST_10_PK='Your test account 10 private key, without 0x'
...
gasReporter: {
...
coinmarketcap:'[Your coinmarketcap.com api-key]',
gasPriceApi:'https://api.bscscan.com/api?module=proxy&action=eth_gasPrice&apikey=[Your bscscan.com api-key]'
...
}
...
ChainLink VRF
For local testing, you need to deploy the ChainLink VRF simulated contract yourself and execute the callback operation yourself. For specific operations, see the official documentation.
Start the local bsc test environment
#Open a terminal in the project root directory and execute
npx hardhat node --fork bsc
Run commands
#Open a second terminal in the project root directory, you can run hardhat commands
#Compile sol files
npx hardhat compile
#Execute ts script under scripts, use local environment
npx hardhat run ./scripts/deploy_raffle.ts --network localhost
#If you want to use other environments, just specify the environment alias after --network, environment aliases are defined in the config of hardhat.config.ts
#For example, if you want to deploy and execute the contract on bsctest, you can run
npx hardhat run ./scripts/deploy_raffle.ts --network bsctest
Run test script
# Open a third terminal in the project root directory, you can run hardhat test commands
# Execute ts script in test, use local environment
npx hardhat test ./test/RaffleRush.ts --network localhost
# If you want to use other environments, just specify the environment alias after --network, environment aliases are defined in the config of hardhat.config.ts
# For example, if you want to test on bsctest, you can run
npx hardhat test ./test/RaffleRush.ts --network bsctest
Before deployment
You need to create a subscription in ChainLink’s background, then fill in the subscription id and coordinator address in the deployment scriptscripts/deploy_raffle.ts
Official documentation
Deploy
npx hardhat run ./scripts/deploy_raffle.ts --network bsc
The contract address printed on the console is the contract address you deployed this time.
After deployment
Remember to add the deployed address to ChainLink’s consumer list