Do you remember when you were a kid and you were using your toys to create legendary fights
?
Have you ever thought on betting and earning real money on
fair imagination battles
with your friends?
Are you too busy
to play with your imagination like when you were a kid but you wish you had the time
for it?
Well say no more, we present... PROMPT FIGHTERS
❗
Click on the image to watch the video on Youtube
.
Technologies implemented here, links go directly to code line on files:
Chainlink Functions
: eth-PromptFighters.sol, FightExecutor.solChainlink CCIP
: CcipNftBridge.solChainlink Automation
: FightMatchmaker.solChainlink VRF
: FightExecutor.solThe Graph
: SubgraphAI related
: mintFighter.js, fightings.js, validateNftPrompt, fightGenerationPrompt
What each technology brings to the table 🧑💻 🆕
Read technical details and see architecture diagrams at docs.
- Chainlink VRF: deciding fair winners
- Chainlink CCIP: automating process in cheaper chains. (Like Avalanche)
- Chainlink Functions: Calling APIs to generate NFTs and make them fight in amazing scenarios.
- Chainlink Automation (up-keeps): Automating the fight process for those who have no time to play but some time in the night to read the amazing fight stories before sleep.
- OpenAI - APIs: To generate interesting fight stories and NFT images.
- The Graph Indexer: for cheaper, faster matchmaking and events tracking in website.
Check the full-stack source code at src
During our project's development, we detected and thought of potential enhancements and problems using Chainlink Services, particularly Chainlink Functions and Chainlink CCIP.
💌
-
Library support in Deno files, especially for hashing (notably keccak256) and asymmetric encryption (ECDSA). Additionally, the addition of a library that simplifies the retrieval of logs from previous blocks would have helped a lot in optimizing and scaling the automated matchmaking and fight system while keeping costs low.
Practical Application:
- In our project, implementing hashing would enable private, unique NFT prompts. Currently, NFT prompts are public, allowing duplication. Hashing prompts in Function scripts would allow on-chain storage of hashes and off-chain verification of prompt ownership by the DON, improving privacy and reducing NFT creation costs.
-
Allow for longer HTTP-API calls. AIs that generate images or a bit long outputs like stories take more than the current limit of 9s. Thus we had to mock in Funtions a response simulating an actual AI-API call. Regardless of this the code that would be used if this restriction didn't exist is added in the project.
-
A tool for simulating DONs reponses in local with forked Chainlink contracts would be very helpful for easier debugging and testing. We don't know if this tool already exists, but we think it would be very useful. Whether an SDK or a UI app on chainlink's website.
With CCIP
:
- Difficulty integrating CCIP with
forge
-based projects. - Variable clash (
i_router
) when using Functions and CCIP concurrently. - Non-virtual
supportsInterface()
function inCCIPReceiver.sol
, creating inheritance conflicts in contrats that inherit different contracts using the EIP-165. (e.g., eth-PromptFightersNFT.sol). AlsosupportsInterface()
is defined aspure
and when mixed with othersupportsInterface()
functions like ERC721 OpenZeppelin's implementation creates a conflict as OZ's one isview
.
With Automation
:
- We have automation coded in our project but it is only working if upkeep is registered via UI. We don't know whats wrong with our registration code everything looks fine. It's a weird error explained in this file on scripts directory..
📘Noteℹ️: The whole team met in the SmartCon 2023, thanks for the great event and the chairs! 😄
Mechanics 📜
Read the details of all mechanics, future scenarios, and its reason why at whitepaper.
- Personalized NFTs : describe your NFT as you want over a template.
- NFT creation AI filtered : so there are no too powerful or copyright infringement prompts.
- Fight and bet against other NFTs.
- Automated Fighting : send some funds and enjoy the fight automation.
Local set-up ⚙️
- Clone the Repository
git clone https://github.com/CarlosAlegreUr/ConstellationChainlinkHackathon2023.git
- Initialize foundry, forge and dependencies
cd ./ConstellationChainlinkHackathon2023/src/backend
foundryup
forge init --force --no-commit
forge install --no-commit OpenZeppelin/openzeppelin-contracts@932fddf69a699a9a80fd2396fd1a2ab91cdda123
forge install --no-commit smartcontractkit/chainlink@cdb0c6a6089d3a69dd09a9b0a9fbdd070eaeb442
# Chainlink ccip contracts cant be installed with forge
# Use this to install CCIP contracts in "./src/backend" (you should already be here)
# Just leave everythin empty and press enter
cd lib
npm init
npm install @chainlink/contracts-ccip --save
# Change the name to node_modules_ccip
mv ./node_modules ./node_modules_ccip
# Notice ℹ️ you can remove package.jon and package-lock.json
# if you want.
The /lib directory should now look like this:
Note
⚠️ Current Chainlink Functions only allows for 9s long HTTP-API calls. Our fight generation requires more than 9s thus we have mocked in the backend a node from a DON executing Chainlink Functions. Functions for NFT validation does work and is implemented interacting with the real DON.
Run the DON mock:
The DON mocker that listens for figths is a scripts
that's found inside next.js project, inside the folder figthListener
First construct the .env
cd src/prompt-figthers/figth-listener/
Inside this folder you will find an example.env
Create an .env
with the values required
# create the env file
touch .env
# edit it with the best text editor ever
nvim .env
And now we can run the script
# root of next.js project
cd ../..
# This requires node
npm run donMock
- Running the Frontend
All the backend is ready to so now execute the front-end locally:
# cd to the front end directory
cd src/prompt-fighters
yarn install
yarn dev
Run scripts' instructions in here: scripts.
Run tests' instructions in here: tests.
3 of us are seeking for job opportunities inside the blockchain world. If you have any for us we would be very happy to hear from you.
-
Carlos Alegre
: Full-stack developer and auditor Github | Linked-In -
Antonio Rodríguez-Ynyesto
Full-stack developer mainly interested in Smart Contracts. Github | Linked-In -
Ethan Rouimi
Full-stack developer and a web3 fanatic. Github | Linked-In