DEV Community

Cover image for 🧠 How I Combined OpenAI, Rust, and Solana: a Quiz That Pays You in Tokens
Dima Zaichenko
Dima Zaichenko

Posted on

🧠 How I Combined OpenAI, Rust, and Solana: a Quiz That Pays You in Tokens

What if every correct answer in a quiz rewarded you with crypto?

I decided to test this idea and built Solana Quiz - a decentralized app where users answer daily quiz questions generated by OpenAI and earn Solana tokens for correct answers.

Yes, it really works. And yes - we even mint our own token 😎.


πŸš€ The Idea

I’ve long wanted to combine AI, Rust, and blockchain into a single project where each piece actually works, not just β€œfor show.”

The result:

  • OpenAI generates fresh questions daily.
  • Node.js checks answers and handles the business logic.
  • Rust mints tokens on Solana.
  • Kafka ties all the services together in a clean event-driven system.

The outcome? A smart, fair, and transparent quiz where rewards don’t land in your email - they land in your Phantom Wallet.


πŸ’‘ How It Works

1️⃣ Solana Wallet Authentication

Users connect their Phantom Wallet and sign a message. Node.js verifies the signature and confirms wallet ownership.

No passwords, tokens, or logins - just pure blockchain authentication.

Currently, only Phantom Wallet is supported, but adding more wallets is possible.


2️⃣ Questions Powered by OpenAI

Every morning, Node.js queries the OpenAI API (gpt-4.1-nano) to get a new set of questions.

OPEN_AI_API_KEY=your_openai_api_key_here
OPEN_AI_MODEL=gpt-4.1-nano
OPEN_AI_LANGUAGE=English
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ You need an OpenAI account and API key. Without it, the quiz stays silent πŸ€–

The questions are varied: from blockchain history to logic puzzles.


3️⃣ Checking Answers & Rewards

Once the quiz is submitted, Node.js publishes an event to Kafka, and the Rust worker listens for it. It then connects to Solana RPC and… πŸ’Έ sends tokens straight to your wallet.

Every correct answer instantly becomes real crypto on the blockchain.


πŸ— Architecture

Service Technologies Description
Frontend Next.js, React, TailwindCSS User interface and wallet integration
Backend Node.js, Express, Prisma, KafkaJS, OpenAI API Quiz logic, question generation, API
Rust Worker Rust, Solana SDK, rdkafka Token minting and Solana transactions
Database PostgreSQL User data and quiz results storage
Infra Docker Compose Service orchestration

πŸͺ™ Creating Your Own Token

The heart of the quiz is a custom SPL token on Solana. This isn’t just a demo coin - it powers the whole quiz economy and makes the reward system transparent and decentralized.

⚠️ Before running the Rust commands, make sure your .env file is ready:

SOLANA_NETWORK=devnet
SOLANA_RPC_ENDPOINT=https://api.devnet.solana.com
SOLANA_AUTHORITY_KEYPAIR_PATH=./secret/authority.json
SOLANA_MINT_KEYPAIR_PATH=./secret/mint.json
SOLANA_TOKEN_NAME="Solana Quiz Token"
SOLANA_TOKEN_SYMBOL="SQT"
SOLANA_TOKEN_METADATA_URI="https://raw.githubusercontent.com/di-zed/internal-storage/refs/heads/main/solana-quiz-token/metadata.json"
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Important: You can change the token name, symbol, description, and metadata - it’s your token, your universe.


πŸš€ Step-by-step: Minting your own Solana token

Let's go through the full process β€” from building the binary to minting your first million tokens πŸͺ™

# πŸ¦€ Enter the Rust container
docker-compose exec rust /bin/bash

# βš™οΈ Build the release binary
cargo build --release

# πŸ’§ Request some SOL for your authority account
./target/release/solana request-airdrop --sol-amount 5

# πŸͺ™ Create a new token mint
./target/release/solana create-mint

# πŸ’Ό Create a token account to store your tokens
./target/release/solana create-token-account

# πŸ’° Mint 1,000,000 tokens
./target/release/solana mint-tokens --amount 1000000
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ These tokens are your reward bank β€”
every time someone answers correctly in the quiz, the Rust worker distributes tokens from this pool.

To make your token display nicely in Phantom Wallet and Solana Explorer, add metadata such as:

https://raw.githubusercontent.com/di-zed/internal-storage/refs/heads/main/solana-quiz-token/metadata.json


🧠 Why Rust

Rust is perfect for working with the Solana SDK - safe, async-friendly, and memory-safe.

Even if you were a bit intimidated by Rust before, this project will make it your new crypto buddy πŸ¦€.


πŸ’Ž Use Cases

  • πŸŽ“ EdTech: tokenize learning - correct answers = real rewards.
  • 🏒 Corporate quizzes: motivate employees with tokens.
  • 🌐 Crypto communities: daily activities and rewards on Solana.
  • πŸ’° Loyalty & gamification: on-chain incentives for engagement.

🧭 Roadmap

  • πŸ† NFT rewards - issue NFTs for streaks of correct answers.
  • πŸ”— Solana Program - store quiz history and auto-distribute NFTs.
  • πŸš€ Mainnet-beta migration.

The Solana program will eventually track quiz history on-chain and automatically reward users who maintain a streak (e.g., 7 days in a row).

NFTs can be created manually via Metaplex - your collection, your designs, your rewards 🎨


🧩 A Bit of Technical Info

I didn’t dive into setup commands in this article - we want it to be easy to read πŸ˜„

If you want to actually run the project, mint your own token, connect OpenAI, and see Solana deliver real rewards - check the README on GitHub.

It has step-by-step instructions, .env examples, and Docker, Rust, and Node.js commands - everything you need to dig deeper.


🧱 Bottom Line

Solana Quiz isn’t a demo or experiment. It’s a live app where AI, Rust, and blockchain work together:

  • OpenAI generates content
  • Node.js manages logic
  • Kafka connects everything
  • Rust handles real transactions

The result? A fair reward system where knowledge brings you crypto, not just points.


βš™οΈ The project runs entirely via Docker - clone the repo, follow the README, and you’re good to go. Everything is covered, including key generation and OpenAI/Solana setup.

πŸ“¦ GitHub: github.com/di-zed/solana-quiz

πŸ“œ License: MIT

✍️ Author: @di-zed

Top comments (0)