The Racing contract is currently deployed and verified on Avalanche Fuji at the following address:
0x143989DeA4CdB29b452b241eF3134d2554E583Bc
The smart contracts for Fury Racing have been implemented in Solidity with the help of the Foundry framework. All the critical features are executed on-chain and handled directly in the contracts. They have been designed with the following goals in mind:
- Reduce the use of arrays and loops as much as possible to be sustainable in the long run;
- Require a single transaction per game (registration included) to keep the UI/UX smooth and user-friendly;
- Gas efficiency and security (Slither/Aderyn);
Chainlink features are leveraged in two ways:
- Chainlink VRF V2.5: to generate random numbers for the luck attributes;
- Chainlink Functions: to query the backend for race results (the time per player based on their car attributes) as well as for weather conditions converted to a percentage;
- Chainlink Automation: to automate the updates of each circuit's weather in the smart contract every hour.
Thanks to Chainlink, the entire logic can stay on-chain and transparent, while the heavy calculations are done off-chain. This allows for more transparency and a more secure, gas-efficient contract. Automation also eliminates the need for a third party to update the weather conditions, removing the requirement to store a private key at the same time.
Make sure to have the following installed on your machine:
- git
- You'll know you did it right if you can run
git --version
and you see a response likegit version x.x.x
- You'll know you did it right if you can run
- foundry
- You'll know you did it right if you can run
forge --version
and you see a response likeforge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
- You'll know you did it right if you can run
Start by cloning the repository and navigating to the project directory:
git clone https://github.com/Pedrojok01/fury-racing.git
cd contracts
Then install the dependencies:
make install
You should now have chainlink
, openzeppelin-contracts
, and forge-std
installed in your lib
folder.
Thanks to the make file, all actions are easily accessible:
- To compile the contracts, run:
make build
- To run the tests, run:
make test
You can even run slither
and aderyn
if they are installed on your machine:
make slither
make aderyn
- To get the test coverage:
make coverage
- To format the solidity code:
make format
Before deploying the contracts, you will need to create your subscriptions to get your subscription IDs. Just follow the instructions for each service:
- Chainlink VRF: https://vrf.chain.link/
- Chainlink Functions: https://functions.chain.link/
Add your contract as a consumer, then fund the subscription with some LINK tokens. You can get some testnet LINK tokens from the Chainlink Faucet: https://faucets.chain.link/
Finally, once you're done setting up the subscriptions, you can update the contract with the new subscription IDs:
When you are ready to deploy the contracts, first ensure that you have updated the values in the scripts/deployerTestnet.sol
file to match your Chainlink VRF and Functions Subscriptions.
Then, go to https://catapulta.sh/ to get your API key. This is a super cool service to deploy and verify your contracts on multiple networks.
Update the environment variables in the .env
file with the required value:
PRIVATE_KEY=
AVALANCHE_RPC_URL=
AVALANCHE_FUJI_RPC_URL=
CATAPULTA_API_KEY=
CATAPULTA_SENDER=
Then run:
make CatapulTest
You should see your contracts address in the console, and a link to the explorer with your contracts verified!
Chainlink Automation setup is a bit different since you must have your contract address to set the function that you want to call. Once you have the contract address, you can follow the instructions there:
- Chainlink Automation: https://automation.chain.link/
Once that's done, don't forget to set the forwarder
address to your Upkeep address
in your contract to make sure that only the Chainlink Automation can update the weather conditions.
And... that's it! You are ready to start racing!