Backend
Description:
The backend part of Fury Racing is quite small, so it has been implemented using AWS Lambda functions and CloudWatch BridgeEvents. The backend is responsible for the following tasks:
Leaderboard: as the leaderboard requires reading a lot of data from the blockchain, as well as sorting those data, it was both simpler and more efficient to implement it as a backend function, leveraging multicall to reduce the number of requests to the node provider.
Race Results: The time generated for each player based on their selected attributes is also handled in the Lambda function. This endpoint is the heart of the backend and is directly queried by the smart contracts when needed via Chainlink Functions.
Weather: The weather for each track is stored on-chain in the smart contracts. The weather is fetched and converted into a percentage by the backend, then a Chainlink Function is in charge of querying the API endpoint. Chainlink Automation has been implemented to trigger an update every hour so the weather is almost in real-time.
Time Calculation:
Each attribute has 3 positive and 3 negative factors that affect the time calculation. The positive factors amplify each other, while the negative ones neglect their effect. The description can be found below:
Calculating the Time:
Lap Time Calculation: For each lap, the car's attributes, track data, and weather conditions are used to calculate the lap time. The calculation considers the positive and negative factors for each attribute.
Total Race Time: The total race time is calculated by summing the lap times for 10 laps.
Random Variability: A random variability factor based on driver skills is applied to each lap time to simulate realistic race conditions.
Example:
Set 1
91488.25
Set 2
91432.10
Set 3
92029.33
Set 4
91802.90
Set 5
92472.82
Built With:
The main technologies used in the backend are:
Node.js: to write the functions
Express.js: to handle the API requests
Viem: to communicate with the smart contracts
AWS Lambda: to host the functions
Serverless Framework: to deploy the functions
Chainlink Functions & Chainlink Automation: to schedule the cron jobs and update the weather every hour
Getting Started
To get started with the backend, you need to install the dependencies:
You can run the tests to see some simulation examples based on different car attribute sets and weather conditions with the following command:
Then you can deploy the function to AWS by running the following command:
Note: you need to have the AWS CLI installed and configured on your machine.
Once deployed, don't forget to add the environment variables to the Lambda function. You can find the list of environment variables in the .env.example
file.
Last updated
Was this helpful?