AI Fortune NFT: A Technological Journey Inspired by Fortune Cookies | by Serkan Erkan | Jan, 2024

Imagine the fortune cookie you crack open after a meal at your favorite Chinese restaurant, bringing a smile to your face with its short and mysterious message. Now imagine how this simple pleasure has evolved with technology. This was the first thing that came to mind when I thought of developing a project using artificial intelligence and blockchain technologies.

At the core of the project is the idea of offering short fortune texts generated instantaneously using an AI-powered language model, along with corresponding visuals, as a unique and unpredictable NFT experience. The inspiring idea from fortune cookies forms the fun and innovative structure of the project. In this article, I will discuss the fundamental components and working method of AI Fortune NFT.

AI Fortune NFT Samples — 2

1) User Interface: Frontend

The user interface (frontend) of the AI Fortune NFT project is designed focusing on user interaction and developed in a structure supporting Web3 technologies. This structure allows users to mint Non-Fungible Tokens (NFTs) on the Polygon network, creating a unique record on the blockchain. Users can also view NFTs previously created. (Polygon is compatible with Ethereum Virtual Machine -EVM-, allowing Ethereum-based smart contracts and applications to run smoothly and is a more cost-effective alternative blockchain. Its currency is Matic, approximately 0.8 USD as of the writing date.)

Screenshot of the user interface

The frontend is developed using jQuery, HTML, and CSS. jQuery, as a fast and effective JavaScript library, supports the dynamic and interactive features of the user interface. The structure and stylization of the frontend are provided with HTML and CSS, while the Bootstrap framework offers a user-friendly experience adaptable to different screen sizes.

Interaction with the Polygon network and Web3 functions are integrated with the ether.js library. Support for MetaMask, a digital wallet, is provided for user consent during NFT production and payment processing.

Payment of the minting fee with MetaMask

Another important feature of the frontend is to process the necessary data for the NFT minting process on the server side and transmit the processed data to the smart contract on the blockchain. This shows that the frontend serves not just as a user interface but also as a critical bridge between the backend and the blockchain. Through this bridge, the entire minting process is carried out smoothly, securely, and efficiently.

2) Server Side: Backend

The server side (backend) of the AI Fortune NFT project is created using Google Cloud Functions, which is offered by Google Cloud Platform (GCP) and based on a serverless architecture. This serverless solution provides flexibility in resource management and operates efficiently even in high traffic situations due to its automatic scaling feature. The main tasks of the backend are:

  • AI-Powered Text Writing: Requests are sent to the OpenAI API based on requests and parameters from the frontend. This API uses the AI-powered GPT-3.5-turbo language model to generate fortune texts in the language chosen by the user on the frontend. As of the writing date, 12 different language options are offered to the user on the frontend, but this number can easily be increased beyond the 60 languages supported by GPT-3.5-turbo.
  • AI-Powered Text-to-Image Transformation: The generated fortune texts are converted into visual content in the style of traditional tarot cards using the OpenAI Dall-E 3 API. This visual content makes the NFTs to be created with the fortune text impressive.
  • Determining the NFT Title and Preparing the JSON File: A unique title is determined for each NFT, and the final JSON file necessary for NFT production is prepared. This file contains metadata information such as the NFT’s title, description, and image address.
  • Recording and Hash Value Return on IPFS: The created visual and JSON files are recorded on IPFS (InterPlanetary File System) via an API. Once recorded on IPFS, these files are now stored in a decentralized manner. When the recording process is completed, the generated IPFS hash value is transmitted to the frontend. This hash will represent the unique reference of the NFT on the blockchain.
  • Continuous Communication with GCP Realtime Database: The backend uses GCP’s realtime database to determine unique NFT titles and keep various transaction records.

3) Blockchain Side: Smart Contract

The blockchain contract of the AI Fortune NFT project is made using the Solidity programming language, designed to run on the Polygon network (and other EVM compatible networks). This contract is the cornerstone of the project and has the following features and functions:

  • Creating NFT with IPFS Hash: The contract uses the IPFS hash value transmitted from the frontend to create unique fortune NFTs for users in the ERC721 standard. ERC721 standardizes the ownership and transfer of digital assets on the blockchain. This process ensures that the digital assets of users are recorded on the blockchain as owned by them.
  • Minting Fee and Royalty Management: The contract has the ability to set a fee for NFT minting and adjust the percentage of royalties to be earned from NFT sales. These transactions are carried out using the IERC2981 standard, ensuring that a certain percentage of each NFT sale is paid to the original creator.
  • Reentrancy Guard Security: The contract uses the Reentrancy Guard structure to protect against reentrancy attacks. This prevents the same function from being called repeatedly, increasing the contract’s security.
  • Compatibility with Transparent Upgradeable Proxy: The contract is designed to be compatible with OpenZeppelin’s Transparent Upgradeable Proxy feature. This feature allows the contract to be updated after deployment on the blockchain, enabling the project to adapt to future technological developments and needs.
Representation of a completed NFT minting process

These features make the AI Fortune NFT project’s blockchain contract both secure and flexible. The contract adapts to the rapidly evolving nature of Polygon blockchain technology, enhancing the project’s long-term sustainability and offering users a secure, transparent NFT minting and management experience. This configuration successfully manages the complexity and security requirements of the project’s technical infrastructure.

3) Conclusion

Conclusion The ‘AI Fortune NFT’ project, which I developed by integrating innovative technologies like artificial intelligence and smart contracts, has been a valuable experience for me to enhance my skills in these areas. Its flexible and expandable structure will allow me to devote more time to this project in the future and take it further. I hope this project is met with interest by a wide audience and eventually becomes a delightful entertainment tool.

Each fortune NFT, from the moment it is minted, is preserved in the owners’ digital wallets not only as a unique asset but also as a beautiful memory. If you too want to experience owning your AI Fortune NFT, you can do so by visiting https://aifortunenft.web.app/. For this, you will need a MetaMask wallet connected to the Polygon network and containing a small balance.

You can also access the AI Fortune NFTs on their OpenSea NFT marketplace page at https://opensea.io/collection/ai-fortune-nfts. As our community grows, I believe following this unique collection will become even more enchanting and satisfying.

I would be happy to meet in the comments if you have any questions.

Hoping is an important step in life. Everything you do has a consequence. The future depends on what you do. — AI Fortune | TR #2

AI Fortune NFT Samples — 3