Skip to content

Ruiruiz30/monad-prompt-mint

Repository files navigation

PromptMint | AI ๅ›พๅƒ็”Ÿๆˆ NFT ๅนณๅฐ

๐ŸŽจ ไปŽๆ–‡ๆœฌๆ็คบ็”Ÿๆˆ AI ๅ›พๅƒๅนถ้“ธ้€ ไธบ NFT | Generate AI Images from Text Prompts and Mint as NFTs

License: MIT TypeScript Next.js Monad

๐ŸŒ ่ฏญ่จ€ | Language

๐Ÿ‡จ๐Ÿ‡ณ ไธญๆ–‡ | ๐Ÿ‡บ๐Ÿ‡ธ English


ไธญๆ–‡ๆ–‡ๆกฃ

๐Ÿ“– ้กน็›ฎไป‹็ป

PromptMint ๆ˜ฏไธ€ไธชๅŸบไบŽ Web3 ็š„ AI ๅ›พๅƒ็”Ÿๆˆๅ’Œ NFT ้“ธ้€ ๅนณๅฐใ€‚็”จๆˆทๅฏไปฅ้€š่ฟ‡ๆ–‡ๆœฌๆ็คบ็”Ÿๆˆ็‹ฌ็‰น็š„ AI ๅ›พๅƒ๏ผŒๅนถๅฐ†ๅ…ถ้“ธ้€ ไธบ NFT ๅญ˜ๅ‚จๅœจ Monad ๆต‹่ฏ•็ฝ‘ไธŠใ€‚ๅนณๅฐ็ป“ๅˆไบ† AI ๅ›พๅƒ็”Ÿๆˆใ€IPFS ๅˆ†ๅธƒๅผๅญ˜ๅ‚จๅ’Œๆ™บ่ƒฝๅˆ็บฆๅŠŸ่ƒฝ๏ผŒๆไพ›ไปŽๅˆ›ๆ„ๆƒณๆณ•ๅˆฐ NFT ๆ‰€ๆœ‰ๆƒ็š„ๆ— ็ผไฝ“้ชŒใ€‚

โœจ ๆ ธๅฟƒๅŠŸ่ƒฝ

  • ๐ŸŽจ AI ๅ›พๅƒ็”Ÿๆˆ: ไฝฟ็”จ OpenAI DALL-E 3 ไปŽๆ–‡ๆœฌๆ็คบ็”Ÿๆˆ็‹ฌ็‰นๅ›พๅƒ
  • ๐Ÿ”— IPFS ๅˆ†ๅธƒๅผๅญ˜ๅ‚จ: ไฝฟ็”จ Web3.Storage ่ฟ›่กŒๅ›พๅƒๅ’Œๅ…ƒๆ•ฐๆฎ็š„ๅŽปไธญๅฟƒๅŒ–ๅญ˜ๅ‚จ
  • ๐Ÿช™ NFT ้“ธ้€ : ๅœจ Monad ๆต‹่ฏ•็ฝ‘ไธŠๅฐ†็”Ÿๆˆ็š„ๅ›พๅƒ้“ธ้€ ไธบ ERC721 NFT
  • ๐Ÿšซ ้˜ฒ้‡ๅคๆœบๅˆถ: ๆ™บ่ƒฝๅˆ็บฆ้˜ฒๆญข็›ธๅŒๆ็คบ่ฏ้‡ๅค้“ธ้€ 
  • ๐Ÿ’ฐ Gas ไผ˜ๅŒ–: ้ซ˜ๆ•ˆ็š„ๆ™บ่ƒฝๅˆ็บฆ่ฎพ่ฎก๏ผŒ้™ไฝŽไบคๆ˜“ๆˆๆœฌ
  • ๐Ÿ” ้’ฑๅŒ…้›†ๆˆ: ๆ”ฏๆŒไธปๆต Web3 ้’ฑๅŒ…่ฟžๆŽฅ
  • ๐Ÿ“ฑ ๅ“ๅบ”ๅผ่ฎพ่ฎก: ๅฎŒ็พŽ้€‚้…็งปๅŠจ็ซฏๅ’ŒๆกŒ้ข็ซฏ
  • ๐Ÿ” ๆ“ไฝœๅކๅฒ: ๅฎŒๆ•ด็š„็”Ÿๆˆๅ’Œ้“ธ้€ ๅކๅฒ่ฎฐๅฝ•

๐Ÿ› ๏ธ ๆŠ€ๆœฏๆ ˆ

  • ๅ‰็ซฏ: Next.js 15, TypeScript, TailwindCSS
  • ๅŒบๅ—้“พ: Solidity, Hardhat, OpenZeppelin
  • Web3 ้›†ๆˆ: Wagmi, Viem
  • AI: OpenAI DALL-E 3
  • ๅญ˜ๅ‚จ: IPFS via Web3.Storage
  • ็ฝ‘็ปœ: Monad Testnet
  • ๆต‹่ฏ•: Jest, Playwright

๐Ÿš€ 5 ๅˆ†้’Ÿๅฟซ้€Ÿ้ชŒ่ฏ

ๅ‰็ฝฎๆกไปถ

  • Node.js 18+ ๅ’Œ npm
  • Web3 ้’ฑๅŒ…๏ผˆMetaMask ็ญ‰๏ผ‰
  • Monad ๆต‹่ฏ•็ฝ‘ MON ไปฃๅธ

ๅฟซ้€Ÿๅผ€ๅง‹

# 1. ๅ…‹้š†้กน็›ฎ
git clone <repository-url>
cd prompt-mint

# 2. ๅฎ‰่ฃ…ไพ่ต–
npm install

# 3. ้…็ฝฎ็Žฏๅขƒๅ˜้‡
cp .env.example .env.local
# ็ผ–่พ‘ .env.local ๅกซๅ…ฅๅฟ…่ฆ็š„ API ๅฏ†้’ฅ

# 4. ่Žทๅ–ๆต‹่ฏ•็ฝ‘ไปฃๅธ
# ่ฎฟ้—ฎ https://testnet-faucet.monad.xyz

# 5. ้ƒจ็ฝฒๆ™บ่ƒฝๅˆ็บฆ
npm run deploy:testnet

# 6. ๅฏๅŠจๅผ€ๅ‘ๆœๅŠกๅ™จ
npm run dev

ๆ‰“ๅผ€ http://localhost:3000 ๅผ€ๅง‹ไฝ“้ชŒ๏ผ

๐Ÿ“‹ ่ฏฆ็ป†ๅฎ‰่ฃ…ๆŒ‡ๅ—

1. ็Žฏๅขƒๅ‡†ๅค‡

็กฎไฟๆ‚จ็š„็ณป็ปŸๅทฒๅฎ‰่ฃ…๏ผš

2. ้กน็›ฎๅ…‹้š†ๅ’Œไพ่ต–ๅฎ‰่ฃ…

# ๅ…‹้š†้กน็›ฎ
git clone <repository-url>
cd prompt-mint

# ๅฎ‰่ฃ…้กน็›ฎไพ่ต–
npm install

# ็ผ–่ฏ‘ๆ™บ่ƒฝๅˆ็บฆ
npm run compile

3. ็Žฏๅขƒๅ˜้‡้…็ฝฎ

ๅˆ›ๅปบ .env.local ๆ–‡ไปถ๏ผš

cp .env.example .env.local

็ผ–่พ‘ .env.local ๆ–‡ไปถ๏ผŒ้…็ฝฎไปฅไธ‹ๅ˜้‡๏ผš

# API ๅฏ†้’ฅ๏ผˆๅฟ…้œ€๏ผ‰
OPENAI_API_KEY=your_openai_api_key_here
PINATA_API_KEY=your_pinata_api_key_here
PINATA_SECRET_KEY=your_pinata_secret_key_here

# ๆ™บ่ƒฝๅˆ็บฆ้ƒจ็ฝฒ๏ผˆๅฆ‚้œ€้ƒจ็ฝฒ๏ผ‰
PRIVATE_KEY=your_private_key_without_0x_prefix

# ๅ‰็ซฏ้…็ฝฎ๏ผˆๅ…ฌๅผ€๏ผ‰
NEXT_PUBLIC_CONTRACT_ADDRESS=deployed_contract_address
NEXT_PUBLIC_MONAD_RPC_URL=https://testnet-rpc.monad.xyz
NEXT_PUBLIC_CHAIN_ID=10143
NEXT_PUBLIC_APP_NAME=PromptMint
NEXT_PUBLIC_APP_DESCRIPTION=Generate AI images and mint them as NFTs on Monad Testnet

๐Ÿ”‘ ่Žทๅ– API ๅฏ†้’ฅ

OpenAI API ๅฏ†้’ฅ:

  1. ่ฎฟ้—ฎ OpenAI Platform
  2. ๅˆ›ๅปบ่ดฆๆˆทๅนถ็™ปๅฝ•
  3. ่ฟ›ๅ…ฅ API Keys ้กต้ข
  4. ๅˆ›ๅปบๆ–ฐ็š„ API ๅฏ†้’ฅ
  5. ๅคๅˆถๅฏ†้’ฅๅˆฐ OPENAI_API_KEY

Pinata IPFS ๆœๅŠกไปค็‰Œ:

  1. ่ฎฟ้—ฎ Pinata
  2. ๅˆ›ๅปบๅ…่ดน่ดฆๆˆท๏ผˆๆœ‰ 1GB ๅ…่ดนๅญ˜ๅ‚จ๏ผ‰
  3. ่ฟ›ๅ…ฅ API Keys ้กต้ข
  4. ็‚นๅ‡ป "New Key" ๅˆ›ๅปบๆ–ฐ็š„ API ๅฏ†้’ฅ
  5. ็กฎไฟๅ‹พ้€‰ "Pinning Services" ๆƒ้™
  6. ๅคๅˆถ API Key ๅˆฐ PINATA_API_KEY
  7. ๅคๅˆถ Secret Key ๅˆฐ PINATA_SECRET_KEY

ๅค‡็”จๆ–นๆกˆ - Web3.Storage ไปค็‰Œ:

  1. ่ฎฟ้—ฎ Web3.Storage
  2. ๅˆ›ๅปบๅ…่ดน่ดฆๆˆท
  3. ่ฟ›ๅ…ฅ API Tokens ้กต้ข
  4. ๅˆ›ๅปบๆ–ฐไปค็‰Œ
  5. ๅคๅˆถไปค็‰Œๅˆฐ WEB3_STORAGE_TOKEN

4. ่Žทๅ–ๆต‹่ฏ•็ฝ‘ไปฃๅธ

  1. ่ฎฟ้—ฎ Monad ๆต‹่ฏ•็ฝ‘ๆฐด้พ™ๅคด
  2. ่ฟžๆŽฅๆ‚จ็š„้’ฑๅŒ…
  3. ็”ณ่ฏท MON ๆต‹่ฏ•ไปฃๅธ
  4. ็ญ‰ๅพ…ไบคๆ˜“็กฎ่ฎค๏ผˆ้€šๅธธ้œ€่ฆๅ‡ ๅˆ†้’Ÿ๏ผ‰

5. ๆ™บ่ƒฝๅˆ็บฆ้ƒจ็ฝฒ

# ้ƒจ็ฝฒๅˆฐ Monad ๆต‹่ฏ•็ฝ‘
npm run deploy:testnet

# ้ชŒ่ฏๅˆ็บฆ๏ผˆๅฏ้€‰๏ผ‰
CONTRACT_ADDRESS=your_contract_address npm run verify:testnet

้ƒจ็ฝฒๆˆๅŠŸๅŽ๏ผŒๅฐ†ๅˆ็บฆๅœฐๅ€ๆ›ดๆ–ฐๅˆฐ .env.local:

NEXT_PUBLIC_CONTRACT_ADDRESS=your_deployed_contract_address

6. ๅฏๅŠจๅบ”็”จ

# ๅผ€ๅ‘ๆจกๅผ
npm run dev

# ็”Ÿไบงๆž„ๅปบ
npm run build
npm start

๐ŸŒ ็ฝ‘็ปœ้…็ฝฎ

Monad ๆต‹่ฏ•็ฝ‘ไฟกๆฏ

้’ฑๅŒ…้…็ฝฎ

ๅฆ‚้œ€ๆ‰‹ๅŠจๆทปๅŠ  Monad ๆต‹่ฏ•็ฝ‘ๅˆฐ้’ฑๅŒ…๏ผš

  1. ๆ‰“ๅผ€ MetaMask
  2. ็‚นๅ‡ป็ฝ‘็ปœไธ‹ๆ‹‰่œๅ•
  3. ้€‰ๆ‹ฉ"ๆทปๅŠ ็ฝ‘็ปœ"
  4. ๅกซๅ…ฅไธŠ่ฟฐ็ฝ‘็ปœไฟกๆฏ

๐ŸŽฏ ไฝฟ็”จๆŒ‡ๅ—

ๅŸบๆœฌๆ“ไฝœๆต็จ‹

  1. ่ฟžๆŽฅ้’ฑๅŒ…: ็‚นๅ‡ป"่ฟžๆŽฅ้’ฑๅŒ…"้€‰ๆ‹ฉๆ‚จ็š„ Web3 ้’ฑๅŒ…
  2. ๅˆ‡ๆข็ฝ‘็ปœ: ็กฎไฟ่ฟžๆŽฅๅˆฐ Monad ๆต‹่ฏ•็ฝ‘
  3. ่พ“ๅ…ฅๆ็คบ่ฏ: ่พ“ๅ…ฅๆ่ฟฐๆ€ง็š„ๆ–‡ๆœฌๆ็คบ๏ผˆๆ”ฏๆŒไธญ่‹ฑๆ–‡๏ผ‰
  4. ็”Ÿๆˆๅ›พๅƒ: ็‚นๅ‡ป"็”Ÿๆˆ"็ญ‰ๅพ… AI ๅค„็†๏ผˆ็บฆ 30-60 ็ง’๏ผ‰
  5. ้ข„่งˆๅ›พๅƒ: ๆŸฅ็œ‹็”Ÿๆˆ็š„ๅ›พๅƒ๏ผŒๆปกๆ„ๅŽ็ปง็ปญ
  6. ้“ธ้€  NFT: ็‚นๅ‡ป"้“ธ้€ "ๅˆ›ๅปบๆ‚จ็š„ NFT๏ผˆ้œ€่ฆ Gas ่ดน๏ผ‰
  7. ๆŸฅ็œ‹ไบคๆ˜“: ๅœจ Monad ๆต่งˆๅ™จ ๆŸฅ็œ‹ไบคๆ˜“

ๆœ€ไฝณๅฎž่ทต

ๆ็คบ่ฏๅปบ่ฎฎ:

  • ไฝฟ็”จๆ่ฟฐๆ€ง่ฏญ่จ€๏ผŒๅŒ…ๅซ้ฃŽๆ ผใ€้ขœ่‰ฒใ€ๆž„ๅ›พ็ญ‰็ป†่Š‚
  • ไพ‹ๅฆ‚๏ผš"ไธ€ๅชๅœจๆ˜Ÿ็ฉบไธ‹ๆผซๆญฅ็š„ๅ‘ๅ…‰็‹ฌ่ง’ๅ…ฝ๏ผŒๆขฆๅนป้ฃŽๆ ผ๏ผŒ่“็ดซ่‰ฒ่ฐƒ"
  • ้ฟๅ…ไฝฟ็”จ่ฟ‡ไบŽ็ฎ€ๅ•็š„ๆ็คบ่ฏ

Gas ่ดนไผ˜ๅŒ–:

  • ๅœจ็ฝ‘็ปœๆ‹ฅๅ ต่พƒๅฐ‘ๆ—ถ่ฟ›่กŒ้“ธ้€ 
  • ้ข„ไผฐ Gas ่ดน็บฆ 0.001-0.01 MON

๐Ÿ”ง ๆ•…้šœๆŽ’้™ค

ๅธธ่ง้—ฎ้ข˜

1. ้’ฑๅŒ…่ฟžๆŽฅ้—ฎ้ข˜

็Žฐ่ฑก: ๆ— ๆณ•่ฟžๆŽฅ้’ฑๅŒ…ๆˆ–็ฝ‘็ปœ้”™่ฏฏ ่งฃๅ†ณๆ–นๆกˆ:

# ๆฃ€ๆŸฅ็ฝ‘็ปœ้…็ฝฎ
- ็กฎไฟ้’ฑๅŒ…่ฟžๆŽฅๅˆฐ Monad ๆต‹่ฏ•็ฝ‘
- ้ชŒ่ฏ RPC URL: https://testnet-rpc.monad.xyz
- ๆฃ€ๆŸฅ้“พ ID: 10143

2. ๅ›พๅƒ็”Ÿๆˆๅคฑ่ดฅ

็Žฐ่ฑก: ็”ŸๆˆๆŒ‰้’ฎๆ— ๅ“ๅบ”ๆˆ–ๆŠฅ้”™ ่งฃๅ†ณๆ–นๆกˆ:

# ๆฃ€ๆŸฅ API ้…็ฝฎ
- ้ชŒ่ฏ OPENAI_API_KEY ๆ˜ฏๅฆๆญฃ็กฎ
- ็กฎ่ฎค API ้…้ขๆœช่ถ…้™
- ๆฃ€ๆŸฅ็ฝ‘็ปœ่ฟžๆŽฅ

3. NFT ้“ธ้€ ๅคฑ่ดฅ

็Žฐ่ฑก: ไบคๆ˜“ๅคฑ่ดฅๆˆ– Gas ไธ่ถณ ่งฃๅ†ณๆ–นๆกˆ:

# ๆฃ€ๆŸฅไฝ™้ขๅ’Œๅˆ็บฆ
- ็กฎไฟ้’ฑๅŒ…ๆœ‰่ถณๅคŸ็š„ MON ไปฃๅธ
- ้ชŒ่ฏๅˆ็บฆๅœฐๅ€ๆ˜ฏๅฆๆญฃ็กฎ
- ้‡่ฏ•ไบคๆ˜“๏ผˆๅฏ่ƒฝ้œ€่ฆ็ญ‰ๅพ…็ฝ‘็ปœ็กฎ่ฎค๏ผ‰

4. IPFS ไธŠไผ ๅคฑ่ดฅ

็Žฐ่ฑก: ๅ›พๅƒ็”ŸๆˆๆˆๅŠŸไฝ†ไธŠไผ ๅคฑ่ดฅ ่งฃๅ†ณๆ–นๆกˆ:

# ๆฃ€ๆŸฅๅญ˜ๅ‚จ้…็ฝฎ
- ้ชŒ่ฏ WEB3_STORAGE_TOKEN ๆ˜ฏๅฆๆœ‰ๆ•ˆ
- ๆฃ€ๆŸฅๅญ˜ๅ‚จ้…้ข
- ้‡่ฏ•ๆ“ไฝœ

้”™่ฏฏไปฃ็ ่ฏดๆ˜Ž

้”™่ฏฏไปฃ็  ๅซไน‰ ่งฃๅ†ณๆ–นๆกˆ
WALLET_CONNECTION ้’ฑๅŒ…่ฟžๆŽฅๅคฑ่ดฅ ๆฃ€ๆŸฅ้’ฑๅŒ…็Šถๆ€ๅ’Œ็ฝ‘็ปœ
GENERATION_FAILED AI ๅ›พๅƒ็”Ÿๆˆๅคฑ่ดฅ ๆฃ€ๆŸฅ API ๅฏ†้’ฅๅ’Œ็ฝ‘็ปœ
IPFS_UPLOAD_FAILED IPFS ไธŠไผ ๅคฑ่ดฅ ๆฃ€ๆŸฅๅญ˜ๅ‚จไปค็‰Œ
MINTING_FAILED NFT ้“ธ้€ ๅคฑ่ดฅ ๆฃ€ๆŸฅ Gas ๅ’Œๅˆ็บฆๅœฐๅ€
PROMPT_ALREADY_USED ๆ็คบ่ฏๅทฒ่ขซไฝฟ็”จ ๅฐ่ฏ•ไธๅŒ็š„ๆ็คบ่ฏ

ๅผ€ๅ‘่ฐƒ่ฏ•

# ๆŸฅ็œ‹่ฏฆ็ป†ๆ—ฅๅฟ—
npm run dev

# ่ฟ่กŒๆต‹่ฏ•
npm test
npm run test:contracts

# ๆฃ€ๆŸฅๆž„ๅปบ
npm run build

# ๆŸฅ็œ‹็ฝ‘็ปœ็Šถๆ€
curl -X POST https://testnet-rpc.monad.xyz \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

๐Ÿงช ๆต‹่ฏ•

่ฟ่กŒๆต‹่ฏ•

# ๅ‰็ซฏๅ•ๅ…ƒๆต‹่ฏ•
npm test

# ๆ™บ่ƒฝๅˆ็บฆๆต‹่ฏ•
npm run test:contracts

# ็ซฏๅˆฐ็ซฏๆต‹่ฏ•
npx playwright test

# ๆต‹่ฏ•่ฆ†็›–็އ
npm run test:coverage

ๆต‹่ฏ•็Žฏๅขƒ

้กน็›ฎๅŒ…ๅซๅฎŒๆ•ด็š„ๆต‹่ฏ•ๅฅ—ไปถ๏ผš

  • ๅ•ๅ…ƒๆต‹่ฏ•: ็ป„ไปถๅ’Œ้’ฉๅญๅ‡ฝๆ•ฐๆต‹่ฏ•
  • ้›†ๆˆๆต‹่ฏ•: API ็ซฏ็‚นๆต‹่ฏ•
  • ๅˆ็บฆๆต‹่ฏ•: ๆ™บ่ƒฝๅˆ็บฆๅŠŸ่ƒฝๆต‹่ฏ•
  • E2E ๆต‹่ฏ•: ๅฎŒๆ•ด็”จๆˆทๆต็จ‹ๆต‹่ฏ•

๐Ÿ“š API ๆ–‡ๆกฃ

REST API ็ซฏ็‚น

POST /api/generate

็”Ÿๆˆ AI ๅ›พๅƒๅนถไธŠไผ ๅˆฐ IPFS

่ฏทๆฑ‚ไฝ“:

{
  "prompt": "ๆ‚จ็š„ๅ›พๅƒๆ่ฟฐๆ็คบ่ฏ"
}

ๅ“ๅบ”:

{
  "success": true,
  "tokenURI": "ipfs://...",
  "previewURL": "https://...",
  "metadata": {
    "name": "AI Generated NFT",
    "description": "Generated from prompt: ...",
    "image": "ipfs://...",
    "attributes": [...]
  }
}

GET /api/health

ๆฃ€ๆŸฅ API ๆœๅŠก็Šถๆ€

ๅ“ๅบ”:

{
  "status": "healthy",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

ๆ™บ่ƒฝๅˆ็บฆๆŽฅๅฃ

ไธป่ฆๅ‡ฝๆ•ฐ

// ้“ธ้€  NFT
function mint(bytes32 promptHash, string memory tokenURI) external

// ๆฃ€ๆŸฅๆ็คบ่ฏๆ˜ฏๅฆๅทฒไฝฟ็”จ
function isPromptUsed(bytes32 promptHash) external view returns (bool)

// ่Žทๅ–ๅฝ“ๅ‰ไปฃๅธ่ฎกๆ•ฐ
function tokenCounter() external view returns (uint256)

// ่Žทๅ–ๆ€ปไพ›ๅบ”้‡
function totalSupply() external view returns (uint256)

// ๆ‰น้‡ๆŸฅ่ฏขไปฃๅธ URI
function tokenURIBatch(uint256[] memory tokenIds) external view returns (string[] memory)

๐Ÿค ่ดก็ŒฎๆŒ‡ๅ—

ๅผ€ๅ‘ๆต็จ‹

  1. Fork ้กน็›ฎๅˆฐๆ‚จ็š„ GitHub ่ดฆๆˆท
  2. ๅˆ›ๅปบๅŠŸ่ƒฝๅˆ†ๆ”ฏ: git checkout -b feature/your-feature
  3. ๆไบคๆ›ดๆ”น: git commit -am 'Add some feature'
  4. ๆŽจ้€ๅˆ†ๆ”ฏ: git push origin feature/your-feature
  5. ๅˆ›ๅปบ Pull Request

ไปฃ็ ่ง„่Œƒ

# ไปฃ็ ๆฃ€ๆŸฅ
npm run lint

# ไปฃ็ ๆ ผๅผๅŒ–
npm run format

# ็ฑปๅž‹ๆฃ€ๆŸฅ
npm run type-check

ๆไบค่ง„่Œƒ

ไฝฟ็”จ็บฆๅฎšๅผๆไบคๆ ผๅผ๏ผš

  • feat: ๆ–ฐๅŠŸ่ƒฝ
  • fix: ้”™่ฏฏไฟฎๅค
  • docs: ๆ–‡ๆกฃๆ›ดๆ–ฐ
  • style: ไปฃ็ ๆ ผๅผ
  • refactor: ้‡ๆž„
  • test: ๆต‹่ฏ•็›ธๅ…ณ
  • chore: ๆž„ๅปบ่ฟ‡็จ‹ๆˆ–่พ…ๅŠฉๅทฅๅ…ท็š„ๅ˜ๅŠจ

๐Ÿ“„ ่ฎธๅฏ่ฏ

ๆœฌ้กน็›ฎ้‡‡็”จ MIT ่ฎธๅฏ่ฏ - ่ฏฆ่ง LICENSE ๆ–‡ไปถใ€‚

๐Ÿ™ ่‡ด่ฐข

ๆ„Ÿ่ฐขไปฅไธ‹ๅผ€ๆบ้กน็›ฎๅ’ŒๆœๅŠก๏ผš

  • OpenZeppelin - ๅฎ‰ๅ…จ็š„ๆ™บ่ƒฝๅˆ็บฆๅบ“
  • Monad - ้ซ˜ๆ€ง่ƒฝๅŒบๅ—้“พๅนณๅฐ
  • OpenAI - AI ๅ›พๅƒ็”ŸๆˆๆœๅŠก
  • Web3.Storage - ๅŽปไธญๅฟƒๅŒ–ๅญ˜ๅ‚จๆœๅŠก

English Documentation

๐Ÿ“– Project Overview

PromptMint is a Web3-based AI image generation and NFT minting platform. Users can generate unique AI images from text prompts and mint them as NFTs on the Monad Testnet. The platform combines AI image generation, IPFS distributed storage, and smart contract functionality to provide a seamless experience from creative ideas to NFT ownership.

โœจ Key Features

  • ๐ŸŽจ AI Image Generation: Generate unique images from text prompts using OpenAI DALL-E 3
  • ๐Ÿ”— IPFS Distributed Storage: Decentralized storage for images and metadata using Web3.Storage
  • ๐Ÿช™ NFT Minting: Mint generated images as ERC721 NFTs on Monad Testnet
  • ๐Ÿšซ Duplicate Prevention: Smart contract prevents duplicate prompts from being minted
  • ๐Ÿ’ฐ Gas Optimized: Efficient smart contract design with reduced transaction costs
  • ๐Ÿ” Wallet Integration: Support for mainstream Web3 wallets
  • ๐Ÿ“ฑ Responsive Design: Perfect adaptation for mobile and desktop
  • ๐Ÿ” Operation History: Complete generation and minting history records

๐Ÿ› ๏ธ Technology Stack

  • Frontend: Next.js 15, TypeScript, TailwindCSS
  • Blockchain: Solidity, Hardhat, OpenZeppelin
  • Web3 Integration: Wagmi, Viem
  • AI: OpenAI DALL-E 3
  • Storage: IPFS via Web3.Storage
  • Network: Monad Testnet
  • Testing: Jest, Playwright

๐Ÿš€ 5-Minute Quick Verification

Prerequisites

  • Node.js 18+ and npm
  • Web3 wallet (MetaMask, etc.)
  • Monad Testnet MON tokens

Quick Start

# 1. Clone the project
git clone <repository-url>
cd prompt-mint

# 2. Install dependencies
npm install

# 3. Configure environment variables
cp .env.example .env.local
# Edit .env.local with your API keys

# 4. Get testnet tokens
# Visit https://testnet-faucet.monad.xyz

# 5. Deploy smart contract
npm run deploy:testnet

# 6. Start development server
npm run dev

Open http://localhost:3000 to start experiencing!

๐Ÿ“‹ Detailed Installation Guide

1. Environment Setup

Ensure your system has:

2. Project Clone and Dependency Installation

# Clone project
git clone <repository-url>
cd prompt-mint

# Install dependencies
npm install

# Compile smart contracts
npm run compile

3. Environment Variable Configuration

Create .env.local file:

cp .env.example .env.local

Edit .env.local file with the following variables:

# API Keys (Required)
OPENAI_API_KEY=your_openai_api_key_here
PINATA_API_KEY=your_pinata_api_key_here
PINATA_SECRET_KEY=your_pinata_secret_key_here

# Smart Contract Deployment (If deploying)
PRIVATE_KEY=your_private_key_without_0x_prefix

# Frontend Configuration (Public)
NEXT_PUBLIC_CONTRACT_ADDRESS=deployed_contract_address
NEXT_PUBLIC_MONAD_RPC_URL=https://testnet-rpc.monad.xyz
NEXT_PUBLIC_CHAIN_ID=10143
NEXT_PUBLIC_APP_NAME=PromptMint
NEXT_PUBLIC_APP_DESCRIPTION=Generate AI images and mint them as NFTs on Monad Testnet

๐Ÿ”‘ Getting API Keys

OpenAI API Key:

  1. Visit OpenAI Platform
  2. Create account and login
  3. Go to API Keys page
  4. Create new API key
  5. Copy key to OPENAI_API_KEY

Pinata IPFS Service Tokens:

  1. Visit Pinata
  2. Create free account (1GB free storage)
  3. Go to API Keys page
  4. Click "New Key" to create new API key
  5. Ensure "Pinning Services" permission is checked
  6. Copy API Key to PINATA_API_KEY
  7. Copy Secret Key to PINATA_SECRET_KEY

Alternative - Web3.Storage Token:

  1. Visit Web3.Storage
  2. Create free account
  3. Go to API Tokens page
  4. Create new token
  5. Copy token to WEB3_STORAGE_TOKEN

4. Get Testnet Tokens

  1. Visit Monad Testnet Faucet
  2. Connect your wallet
  3. Request MON test tokens
  4. Wait for transaction confirmation (usually takes a few minutes)

5. Smart Contract Deployment

# Deploy to Monad Testnet
npm run deploy:testnet

# Verify contract (optional)
CONTRACT_ADDRESS=your_contract_address npm run verify:testnet

After successful deployment, update the contract address in .env.local:

NEXT_PUBLIC_CONTRACT_ADDRESS=your_deployed_contract_address

6. Start Application

# Development mode
npm run dev

# Production build
npm run build
npm start

๐ŸŒ Network Configuration

Monad Testnet Information

Wallet Configuration

To manually add Monad Testnet to your wallet:

  1. Open MetaMask
  2. Click network dropdown
  3. Select "Add Network"
  4. Fill in the network information above

๐ŸŽฏ Usage Guide

Basic Operation Flow

  1. Connect Wallet: Click "Connect Wallet" to select your Web3 wallet
  2. Switch Network: Ensure connection to Monad Testnet
  3. Enter Prompt: Input descriptive text prompt (supports Chinese and English)
  4. Generate Image: Click "Generate" and wait for AI processing (about 30-60 seconds)
  5. Preview Image: Review the generated image, continue if satisfied
  6. Mint NFT: Click "Mint" to create your NFT (requires gas fee)
  7. View Transaction: Check transaction on Monad Explorer

Best Practices

Prompt Suggestions:

  • Use descriptive language including style, colors, composition details
  • Example: "A glowing unicorn walking under starry sky, fantasy style, blue-purple tones"
  • Avoid overly simple prompts

Gas Fee Optimization:

  • Mint during less congested network times
  • Estimated gas fee: ~0.001-0.01 MON

๐Ÿ”ง Troubleshooting

Common Issues

1. Wallet Connection Issues

Symptoms: Cannot connect wallet or network errors Solutions:

# Check network configuration
- Ensure wallet is connected to Monad Testnet
- Verify RPC URL: https://testnet-rpc.monad.xyz
- Check Chain ID: 10143

2. Image Generation Failure

Symptoms: Generate button unresponsive or errors Solutions:

# Check API configuration
- Verify OPENAI_API_KEY is correct
- Confirm API quota not exceeded
- Check network connection

3. NFT Minting Failure

Symptoms: Transaction fails or insufficient gas Solutions:

# Check balance and contract
- Ensure wallet has sufficient MON tokens
- Verify contract address is correct
- Retry transaction (may need to wait for network confirmation)

4. IPFS Upload Failure

Symptoms: Image generation succeeds but upload fails Solutions:

# Check storage configuration
- Verify WEB3_STORAGE_TOKEN is valid
- Check storage quota
- Retry operation

Error Code Reference

Error Code Meaning Solution
WALLET_CONNECTION Wallet connection failed Check wallet status and network
GENERATION_FAILED AI image generation failed Check API key and network
IPFS_UPLOAD_FAILED IPFS upload failed Check storage token
MINTING_FAILED NFT minting failed Check gas and contract address
PROMPT_ALREADY_USED Prompt already used Try different prompt

Development Debugging

# View detailed logs
npm run dev

# Run tests
npm test
npm run test:contracts

# Check build
npm run build

# Check network status
curl -X POST https://testnet-rpc.monad.xyz \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

๐Ÿงช Testing

Running Tests

# Frontend unit tests
npm test

# Smart contract tests
npm run test:contracts

# End-to-end tests
npx playwright test

# Test coverage
npm run test:coverage

Test Environment

The project includes a comprehensive test suite:

  • Unit Tests: Component and hook function tests
  • Integration Tests: API endpoint tests
  • Contract Tests: Smart contract functionality tests
  • E2E Tests: Complete user flow tests

๐Ÿ“š API Documentation

REST API Endpoints

POST /api/generate

Generate AI image and upload to IPFS

Request Body:

{
  "prompt": "Your image description prompt"
}

Response:

{
  "success": true,
  "tokenURI": "ipfs://...",
  "previewURL": "https://...",
  "metadata": {
    "name": "AI Generated NFT",
    "description": "Generated from prompt: ...",
    "image": "ipfs://...",
    "attributes": [...]
  }
}

GET /api/health

Check API service status

Response:

{
  "status": "healthy",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

Smart Contract Interface

Main Functions

// Mint NFT
function mint(bytes32 promptHash, string memory tokenURI) external

// Check if prompt is used
function isPromptUsed(bytes32 promptHash) external view returns (bool)

// Get current token count
function tokenCounter() external view returns (uint256)

// Get total supply
function totalSupply() external view returns (uint256)

// Batch query token URIs
function tokenURIBatch(uint256[] memory tokenIds) external view returns (string[] memory)

๐Ÿค Contributing

Development Workflow

  1. Fork the project to your GitHub account
  2. Create feature branch: git checkout -b feature/your-feature
  3. Commit changes: git commit -am 'Add some feature'
  4. Push branch: git push origin feature/your-feature
  5. Create Pull Request

Code Standards

# Code linting
npm run lint

# Code formatting
npm run format

# Type checking
npm run type-check

Commit Convention

Use conventional commit format:

  • feat: New features
  • fix: Bug fixes
  • docs: Documentation updates
  • style: Code formatting
  • refactor: Refactoring
  • test: Test related
  • chore: Build process or auxiliary tool changes

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

Thanks to the following open source projects and services:

  • OpenZeppelin - Secure smart contract libraries
  • Monad - High-performance blockchain platform
  • OpenAI - AI image generation service
  • Web3.Storage - Decentralized storage service

๐Ÿ“ž Support | ๆ”ฏๆŒ

For questions and support | ๅฆ‚ๆœ‰้—ฎ้ข˜ๅ’Œๆ”ฏๆŒ้œ€ๆฑ‚:

Happy minting! | ็ฅๆ‚จ้“ธ้€ ๆ„‰ๅฟซ๏ผ ๐ŸŽจโœจ

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published