Smart Contracts
Last updated
Was this helpful?
Last updated
Was this helpful?
The Racing contract is currently deployed and verified on Avalanche Fuji at the following address:
The smart contracts for Fury Racing have been implemented in Solidity with the help of the 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 (/);
Chainlink features are leveraged in two ways:
: to generate random numbers for the luck attributes;
: 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;
: 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:
You'll know you did it right if you can run git --version
and you see a response like git version x.x.x
You'll know you did it right if you can run forge --version
and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
Start by cloning the repository and navigating to the project directory:
Then install the dependencies:
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:
To run the tests, run:
You can even run slither
and aderyn
if they are installed on your machine:
To get the test coverage:
To format the solidity code:
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:
Then run:
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!