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)