The purpose of this project is to develop a platform to manage on-chain data for Spanish horse racing so these data can be used by external applications (games, dApps, etc.)
One of this applications, included in the project, is a fully on-chain thoroughbred NFTs representing real race horses that anyone can acquire. The NFTs look like a game card with SVG and horse data. The NFTs are upgradeable with the current number of victories of the horse represented.
In order to fetch horses' data, I have installed a local Chainlink node with a specific jobId that requests the data to Metaturf Spanish horse racing platform. I am partner at this company.
https://dmolinac.github.io/blockchain-developer-bootcamp-final-project/
In order to cover costs, the platform will apply fees when horses are sold, traits are updated and horses are used by external dApps.
I tried to keep the idea as simple as possible, so at this stage the contracts and dApp are in an early stage. Next steps are manyfold:
MetaturfHorseRacingData
address as an argument in MetaturfNFT
constructor.MetaturfHorseRacingData
contract to build other dApps.The dApp is backed by 3 smart contracts:
MetaturfHorseRacingData
contract stores Spanish horse racing data retrieved from a Chainlink oracle. It declares a library with structs to store Horse and Race data.
MetaturfNFT
contract mints NFTs 100% on-chain. Inspired in generative NFTs and Loot project
Oracle
Chainlink base contract for Oracles. Deployed with Remix
npm i -g truffle
npm i @truffle/hdwallet-provider
npm i @openzeppelin/contracts
npm i @chainlink/contracts
npm i -g react
npm i axios
npm i dotenv
client
: Project's React frontend.
contracts
: Smart contracts that are deployed in the Kovan testnet.
migrations
: Migration files for deploying contracts in contracts directory.
test
: Tests for smart contracts.
The development, test and deploy of the contracts and the React dApps have been performed in Kovan testnet, mainly to be able to integrate with the Chainlink oracle.
git clone https://github.com/dmolinac/blockchain-developer-bootcamp-final-project
I have included a file .env.template with the two environment variables to customise:
MNEMONIC="YOUR_MNEMONIC_PHRASE_HERE"
INFURA_API_URL="YOUR_INFURA_API_KEY_HERE"
cd blockchain-developer-bootcamp-final-project
npm install
truffle compile
truffle test --network kovan
truffle deploy --network kovan --reset
The oracle contract is inherited from Chainlink and it is fixed as it needs to call the local Chainlink node. It was deployed using Remix. The address is set in MetaturfHorseRacingData
contract.
In order for the dApp to work, we need to set the address of MetaturfHorseRacingData
contract in MetaturfNFT
contract:
First, we get the address of MetaturfHorseRacingData
address:
npx truffle console --network kovan
truffle(kovan)> let mtdata = await MetaturfHorseRacingData.deployed()
truffle(kovan)> let mtaddress = mtdata.address
Then, we register the address in MetaturfNFT
contract:
truffle(kovan)> let nft = await MetaturfNFT.deployed()
truffle(kovan)> nft.registerMetaturfHorseRacingDataAddress(mtdata.address)
Finally, we need to send LINK tokens (1 LINK per request) to the MetaturfHorseRacingContract
(i.e. using Metamask):
We can check the contract address by typing mtdata.address
in Truffle console.
Some examples:
let result = await mtdata.requestOracleRaceWinner(456)
result.logs[0]
mtdata.setHorseFromCSV("793,VEGIA,3")
Get information from a horse stored: mtdata.getHorse(793)
List horses: mtdata.listHorses()
Mint a horse: nft.mint(12,"Horse_name")
Get NFT Info: nft.getHorseNFTInfo(0);
Get number of tokens: nft.getNumberOfTokens()
The Web Client for the dApp has been developed with React.
cd client
npm install
npm install gh-pages --save-dev
npm run predeploy
npm run deploy
The project interacts with a Chalinlink node installed locally. We have developed the project so it can be operated without this requirement by calling setHorseFromCSV
from MetaturfHorseRacingData
contract (see example above). In case the server is not running, please write to dmolinac@gmail.com.
0xBbc9368898422Cc9FfaBEf8ea66210D3D011512F