Skip to content

Tenyokj/42protocol

Repository files navigation

42 Protocol

Solidity Hardhat Network Tests Coverage License

42 Protocol Logo

Ask Deep Thought any question for 0.042 ETH.

Most of the time, the answer is 42.

Sometimes, it is DON'T PANIC, Bring a Towel, Heart of Gold, Infinite Improbability, or the ultra-rare The Question.

Every question becomes a potential fully on-chain artifact:

  • the question is stored onchain
  • the answer is derived onchain
  • the SVG is generated onchain
  • the metadata is generated onchain
  • the NFT is minted onchain

This repository is prepared for deployment to Base Sepolia.

Table Of Contents

  1. Project Summary
  2. Core Features
  3. How The Protocol Works
  4. Contract Layout
  5. Repository Layout
  6. Quick Start
  7. Environment Variables
  8. Compile, Test, Coverage
  9. Deploy To Base Sepolia
  10. Verification
  11. Documentation Map
  12. Roadmap

Project Summary

42 Protocol is a themed onchain experience inspired by The Hitchhiker's Guide to the Galaxy.

The protocol does one thing very clearly:

  1. a user asks a question
  2. Deep Thought answers it
  3. the answer is immortalized as a fully on-chain NFT

The project is intentionally simple at the interaction layer, but richer under the hood:

  • deterministic seed generation
  • rarity-based answers
  • free-question mechanic when The Question appears
  • modular renderer architecture
  • ERC-721 NFT issuance per question
  • Base64 metadata and Base64 SVG images served entirely onchain

Core Features

Onchain question asking

Users call DeepThought.ask(string) and either:

  • pay 0.042 ETH, or
  • consume a previously earned free-question credit

Answer rarity system

The protocol maps a deterministic seed to one of several answers:

  • 42
  • DON'T PANIC
  • Bring a Towel
  • Heart of Gold
  • Infinite Improbability
  • The Question

Fully on-chain NFT output

Each successful question can mint an NFT that includes:

  • a generated SVG image
  • on-chain JSON metadata
  • rarity traits
  • edition number
  • question id
  • block number
  • timestamp
  • deterministic galaxy seed

Game mechanic

If a user hits the rare The Question result, the protocol awards a free future ask through freeQuestions[address].

That means the rarest answer is not just cosmetic. It changes future user behavior and gives the protocol a small game loop.

How The Protocol Works

Ask flow

  1. The user calls DeepThought.ask(question).
  2. The contract checks whether the user has a free question credit.
  3. If not, the call must include at least 0.042 ETH.
  4. The contract derives a deterministic seed from caller and block data.
  5. The seed is mapped to an AnswerType.
  6. The full question record is stored onchain.
  7. If the answer is The Question, the user earns one free future ask.
  8. If linked contracts are initialized, the protocol mints an NFT through FortyTwoNFT.

Metadata flow

  1. A wallet or marketplace asks FortyTwoNFT.tokenURI(tokenId).
  2. FortyTwoNFT loads the linked question record from DeepThought.
  3. FortyTwoNFT calls MetadataRenderer.generateTokenURI(...).
  4. MetadataRenderer calls SVGRenderer.generateSVG(...).
  5. The final output is returned as: data:application/json;base64,...

Rendering flow

The rendering is split on purpose:

  • SVGRenderer handles image generation
  • MetadataRenderer handles JSON generation
  • FortyTwoNFT handles token ownership
  • DeepThought handles protocol logic

That separation makes the repo easier to reason about, easier to test, and less bloated than a single monolithic contract.

Contract Layout

  • DeepThought.sol Main protocol contract. Price, storage, answer generation, free asks, initialization, withdraw.
  • FortyTwoNFT.sol ERC-721 contract. One NFT per question. Delegates metadata rendering.
  • MetadataRenderer.sol Builds Base64 JSON metadata and traits.
  • SVGRenderer.sol Builds fully on-chain SVG artwork.

Detailed documentation:

Repository Layout

42-protocol/
├── contracts/
│   ├── DeepThought.sol
│   ├── FortyTwoNFT.sol
│   ├── MetadataRenderer.sol
│   ├── SVGRenderer.sol
│   └── mocks/
├── docs/
├── scripts/
├── tasks/
├── test/
├── hardhat.config.ts
├── package.json
└── .env.example

Quick Start

npm install
npm run compile
npm test

Environment Variables

Create .env from .env.example.

Required for Base Sepolia deployment:

BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
DEPLOYER_KEY=
BASESCAN_API_KEY=

Local development:

LOCAL_RPC_URL=http://127.0.0.1:8545

Compile, Test, Coverage

Compile:

npm run compile

Run tests:

npm test

Run coverage:

npx hardhat test --coverage

Current status:

  • 29 passing tests
  • 98.03% line coverage
  • 96.98% statement coverage

Deploy To Base Sepolia

npm run deploy:base-sepolia

The deploy script does:

  1. deploy SVGRenderer
  2. deploy MetadataRenderer
  3. deploy DeepThought
  4. deploy FortyTwoNFT
  5. call DeepThought.setContracts(...)

Local dry-run:

npm run deploy

Verification

Base Sepolia verification command:

npm run verify:base-sepolia -- <contract-address> <constructor-args...>

See the full guide in docs/DEPLOYMENT.md.

Documentation Map

Releases

No releases published

Packages

 
 
 

Contributors