Inspiration

3x Battle Wizards is inspired by randomization of visual and functional components in RPG video games, dark fantasy novels and natively cross-chain games that are yet to come.

What it does

3x Battle Wizards introduces a ERC-721 based smart contract that utilizes a whole suite of Chainlink services to gamify players' experience onchain:

  • Start with 10 Battle Wizards NFTs pre-minted or mint them cross-chain via CCIP.
  • Randomize Attack and Defense of your wizard with Chainlink VRF.
  • Use Chainlink Functions to call DALLE-3 and generate a high quality image of a dark battle wizard for your NFT.
  • Bridge your battle wizard to a different chain via Chainlink CCIP to reset it's stats and start over.

How we built it

First we forked Chainlink CCIP cross-chain NFT smart contract repo to be the starting ground for the project. Then we gradually built in support for onchain and off-chain metadata, randomization of melee attack and defense stats through a Chainlink VRF subscription as well as a bridging mechanism through Chainlink CCIP.

After that we worked on a Flask Python API that makes it very easy to generate wizard images for this onchain game. The API essentially serves as a middleware in-between our smart contract and Open AI API. It is recommended to deploy the API on Google Cloud. You can find the API source code here: https://github.com/exakoss/dalle3-png-chainlink-hackathon-2023

Lastly, we built in Chainlink Functions functionality into the main smart contract, and after combining it all together got the final product, that is ready to be used in onchain games and beyond.

Challenges we ran into

  • Finding an optimal value for gasLimits for both Chainlink VRF and CCIP took some time, but testing on Avalanche Fuji (more on it later in What we learned section) made the testing loop faster and allowed to arrive on the final values relatively early in the development process.
  • Chainlink Functions currently have a pre-set timeout of 5 seconds, and DALLE typically takes around 8-9 seconds to generate and return an image. To solve this problem we created a deterministic route in our API, which serves a generated image after it has been created, and instantly returns "true" to an initial request coming through Chainlink Functions.
  • Originally we wanted to turn generated images from DALLE-3 into onchain .SVG just as the beginner stats, but the .png -> .svg converter built in the API was reducing quality of the images and making the process slower, so eventually we went with .PNG images hosted by Open AI instead.
  • Prompt engineering DALLE-3 to return images that render well on OpenSea and look appealing and high quality was a process of trial error that took some time off coding.

Accomplishments that we're proud of

  • Learning how to use Chainlink services from scratch and successfully putting 3 of them together to get an entertaining and functional product.
  • Combining off-chain capabilities of Open AI API and DALLE-3 together with metadata onchain via Chainlink Functions.
  • Fine tuning the prompt to achieve aesthetically pleasing images generated by DALLE-3.

What we learned

  • Chainlink CCIP is somewhat more modular than other GMP protocols, which allows to abstract bridging logic away into SourceSender.sol and DestinationMinter.sol contracts, which in turn leaves more space for metadata and randomization logic in the NFT smart contract itself.
  • Chainlink provides convenient subscription interfaces for most of its services such as VRF and Functions, that not only allow to use a single subscription with multiple smart contract, but also increases security of the contracts by not having to store any value in them, thus making them less attractive for a potential hacker.
  • Avalanche Fuji is the best testnet for trying out Chainlink technologies, as it has a short finality time which greatly speeds up everything, especially outcoming cross-chain transactions.

What's next for 3x Battle Wizards

  • Embrace randomization via Chainlink VRF even more by introducing more randomly generated stats as well as generated names and origin stories (descriptions) for each Battle Wizard.
  • Potentially expand into a production-ready season-based onchain game where the proceeds from the mint go to a vault that players who hold Battle Wizards compete over.
  • Monetize transactions that generate and re-generate generative art and put it into the metadata in the future for other projects that use Chainlink Functions + AI.

Built With

Share this project:

Updates

Submission history