1단계: 영수증과 보증서12개 검사 통과
- 0 · 로드맵
- 1 · 영수증과 보증
- 2 · 크리에이터 로열티
- 3 · B2B 인보이스
- 4 · 결제 브리지
- 5 · 시뮬레이터
- 6 · Devnet: 직접 재현
- 7 · 계산대
- 7.1 · 안전
- ✓ · 신뢰 사슬
- ★ · 이점과 활용
- ✎ · 열 가지 해설
- ▶ · 영상
- ? · 독자 발견

종이 영수증은 바래고, PDF는 고칠 수 있고, 상점의 데이터베이스는 사라질 수 있습니다. NFT로 발행한 영수증은 위조할 수 없고 구매자에게 남습니다. 이 모델은 WNS가 도입한 토큰 구조 그대로 주문마다 하나씩 발행합니다. 소수점 0자리, 공급량 1로 고정, 메타데이터는 토큰 안에 저장.
과제
모든 고객에게 상점이 잃어버릴 수 없고, 고객이 위조할 수 없고, 공개 체인에서도 사적인 정보를 드러내지 않는 구매 증명을 줍니다. 선택적으로 보증을 그 구매자에게 묶어, 물건을 산 사람과 따로 팔 수 없게 합니다.
모델
- 상점은 주문(번호, 상품, 가격, 날짜)을 SHA-256으로 해시합니다. 체인에는 해시만 올라가고, 주문 자체는 상점 시스템과 고객에게 남습니다.
- Metadata Pointer 확장을 켠 새 Token-2022 민트를 만들어 이름, 심볼, 링크, 추가 필드가 민트 안에 들어갑니다. 외부 메타데이터 계정이 필요 없습니다. 이것이 WNS 방식입니다.
- 추가 필드:
order_hash,warranty_until,sku. - 선택형 Non-Transferable 확장은 영수증을 소울바운드로 만듭니다. 보증은 구매자의 것이며 옮길 수 없습니다.
- 구매자에게 토큰 하나를 발행한 뒤 민트 권한을 제거합니다. 공급량은 영원히 정확히 1개로 고정됩니다.
보증을 확인하려면 누구나 고객이 보여 준 주문을 해시해 체인의 order_hash와 비교하면 됩니다. 일치하면 구매가 증명되고, 날짜 필드가 기간을 증명합니다.
코드
파일: lab/code/src/01-receipt-nft.ts · Apache-2.0
// Model 1: digital receipt and warranty card as a Token-2022 NFT (the same on-chain layout WNS uses:
// zero decimals, supply locked at 1, metadata stored inside the mint).
// License: Apache-2.0. Example code, not audited. Devnet first.
import {
Keypair, PublicKey, SystemProgram, Transaction, sendAndConfirmTransaction, type TransactionInstruction,
} from '@solana/web3.js';
import {
AuthorityType, ExtensionType, LENGTH_SIZE, TOKEN_2022_PROGRAM_ID, TYPE_SIZE,
createAssociatedTokenAccountIdempotentInstruction, createInitializeMetadataPointerInstruction,
createInitializeMintInstruction, createInitializeNonTransferableMintInstruction,
createMintToInstruction, createSetAuthorityInstruction, getAssociatedTokenAddressSync, getMintLen,
} from '@solana/spl-token';
import { createInitializeInstruction, createUpdateFieldInstruction, pack, type TokenMetadata } from '@solana/spl-token-metadata';
import { createHash } from 'node:crypto';
import { getConnection, loadKeypair } from './common.js';
export interface Order {
orderId: string;
sku: string;
priceMinorUnits: number; // e.g. cents
currency: string; // e.g. "USD"
purchasedAt: string; // ISO date
warrantyMonths: number;
}
/** Hash the order so the chain stores proof of purchase, not the customer's personal data. */
export function orderHash(order: Order): string {
return createHash('sha256').update(JSON.stringify(order)).digest('hex');
}
export interface ReceiptOptions { soulbound: boolean; uri: string }
/** Everything needed to size and build the receipt mint. */
export function receiptLayout(order: Order, mint: PublicKey, merchant: PublicKey, opts: ReceiptOptions) {
const warrantyUntil = new Date(order.purchasedAt);
warrantyUntil.setMonth(warrantyUntil.getMonth() + order.warrantyMonths);
const metadata: TokenMetadata = {
mint, updateAuthority: merchant,
name: `Receipt ${order.orderId}`,
symbol: 'RCPT',
uri: opts.uri, // JSON with public, non-personal details
additionalMetadata: [
['order_hash', orderHash(order)],
['warranty_until', warrantyUntil.toISOString().slice(0, 10)],
['sku', order.sku],
],
};
// A soulbound receipt cannot be transferred: good for a warranty tied to one buyer.
const extensions = [ExtensionType.MetadataPointer, ...(opts.soulbound ? [ExtensionType.NonTransferable] : [])];
const mintLen = getMintLen(extensions);
const metadataLen = TYPE_SIZE + LENGTH_SIZE + pack(metadata).length;
return { metadata, mintLen, rentSpace: mintLen + metadataLen };
}
/** Build all instructions: create mint, store metadata, mint 1 to the buyer, lock supply. */
export function buildReceiptInstructions(args: {
order: Order; mint: PublicKey; merchant: PublicKey; buyer: PublicKey; opts: ReceiptOptions; rentLamports: number;
}): { instructions: TransactionInstruction[]; buyerAta: PublicKey } {
const { order, mint, merchant, buyer, opts } = args;
const { metadata, mintLen } = receiptLayout(order, mint, merchant, opts);
const buyerAta = getAssociatedTokenAddressSync(mint, buyer, false, TOKEN_2022_PROGRAM_ID);
const instructions = [
SystemProgram.createAccount({
fromPubkey: merchant, newAccountPubkey: mint, space: mintLen, lamports: args.rentLamports, programId: TOKEN_2022_PROGRAM_ID,
}),
// Metadata lives inside the mint itself: no external metadata account.
createInitializeMetadataPointerInstruction(mint, merchant, mint, TOKEN_2022_PROGRAM_ID),
...(opts.soulbound ? [createInitializeNonTransferableMintInstruction(mint, TOKEN_2022_PROGRAM_ID)] : []),
createInitializeMintInstruction(mint, 0, merchant, null, TOKEN_2022_PROGRAM_ID),
createInitializeInstruction({
programId: TOKEN_2022_PROGRAM_ID, metadata: mint, updateAuthority: merchant, mint, mintAuthority: merchant,
name: metadata.name, symbol: metadata.symbol, uri: metadata.uri,
}),
...metadata.additionalMetadata.map(([field, value]) => createUpdateFieldInstruction({
programId: TOKEN_2022_PROGRAM_ID, metadata: mint, updateAuthority: merchant, field, value,
})),
createAssociatedTokenAccountIdempotentInstruction(merchant, buyerAta, buyer, mint, TOKEN_2022_PROGRAM_ID),
createMintToInstruction(mint, buyerAta, merchant, 1, [], TOKEN_2022_PROGRAM_ID),
// Lock supply at exactly 1: zero decimals + no mint authority = an NFT, as in WNS.
createSetAuthorityInstruction(mint, merchant, AuthorityType.MintTokens, null, [], TOKEN_2022_PROGRAM_ID),
];
return { instructions, buyerAta };
}
/** Send on a real cluster (devnet by default). */
export async function mintReceipt(order: Order, buyer: PublicKey, opts: ReceiptOptions) {
const connection = getConnection();
const merchant = loadKeypair();
const mint = Keypair.generate();
const { rentSpace } = receiptLayout(order, mint.publicKey, merchant.publicKey, opts);
const rentLamports = await connection.getMinimumBalanceForRentExemption(rentSpace);
const { instructions, buyerAta } = buildReceiptInstructions({ order, mint: mint.publicKey, merchant: merchant.publicKey, buyer, opts, rentLamports });
const signature = await sendAndConfirmTransaction(connection, new Transaction().add(...instructions), [merchant, mint]);
return { mint: mint.publicKey.toBase58(), buyerAta: buyerAta.toBase58(), signature };
}
검증한 내용
LiteSVM에서 소울바운드 버전과 전송 가능 버전 모두에 대해: 영수증이 발행되고, 공급량은 정확히 1, 소수점 0자리, 민트 권한 없음, 이름·주문 해시·보증 날짜를 민트 안에서 다시 읽어 내고, 구매자가 보유하며, 소울바운드 영수증은 이동을 거부하고(Token-2022 자체가 거부), 전송 가능 영수증은 선물하거나 되팔 수 있으며, 아무도 두 번째 사본을 발행할 수 없음을 확인했습니다. 검증 기록을 보세요.
쓸모 있는 곳
- 전자제품과 가전: 종이 없는 보증 청구.
- 한정판과 수집품: 첫 판매부터 이어지는 출처 증명.
- 중고 시장: 전송 가능한 영수증이 다음 주인에게 물건의 출처를 보여 줍니다.
- 충성도 프로그램: 영수증 자체가 멤버십 카드가 됩니다.
한계와 위험
- 영수증마다 렌트(소액의 SOL 예치금)와 네트워크 수수료가 듭니다. 대량이라면 묶거나 압축하세요.
- 개인 정보(이름, 주소, 전화번호)를 메타데이터에 절대 넣지 마세요. 체인은 공개되어 있고 영구적입니다.
- 해시는 상점이 해시한 내용만 증명합니다. 시작하기 전에 고정된 주문 형식을 정하세요.
- 구매자에게는 지갑이 필요합니다. 대중 소매라면 수탁형 지갑이나 내장형 지갑 옵션을 계획하세요.
그림으로 보는 Wen
이 모델에서 Wen의 자리
상점은 영수증 NFT 보유자에게 소액의 WEN 팁이나 충성도 보너스를 줄 수도 있고, 4단계를 통해 계산할 때 WEN을 받을 수도 있습니다. 영수증 자체는 Wen이 유명하게 만든 WNS 구조를 씁니다. 첫 WNS NFT는 Meow의 시였고, 같은 구조가 이제 구매 증명을 담습니다.
Wen의 실: 하나의 컨트랙트, 어디에나
랩의 모든 모델은 무료이고 공개되어 있으며, 모두 같은 서명을 지닙니다. 바로 $WEN 토큰 컨트랙트입니다. 복사해 내 문서에도 적어 두고, 쓰기 전에는 반드시 익스플로러에서 확인하세요.
WENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk
확인: Solana Explorer · 컨트랙트 ID 찾는 법
오픈 사용 정책
- 무료이고 공개. 랩의 모든 코드는 Wen Program Library와 같은 Apache License 2.0으로 공개됩니다. 상업적이든 아니든 쓰고, 고치고, 배포하세요. 라이선스 고지만 유지하면 됩니다.
- 오픈 도구만. 공개되어 있고 문서화된 도구로 만듭니다: Solana SPL Token-2022(Token Extensions), Wen New Standard(WNS) 토큰 구조, Solana Pay, 로컬 테스트용 LiteSVM.
- 규칙: 내 모델은 언제나 직접 검증하라. 테스트를 돌리고, devnet에서 시작하고, 공식 문서를 읽고, 모든 계정과 금액을 검토하고, 메인넷에 쓰기 전에 독립 감사를 받으세요. 검증하지 않은 모델은 모델이 아니라 추측입니다.
- 감사받지 않았고, 조언이 아닙니다. 교육용 예제입니다. 금융·법률·세무 조언이 아니며, 인가받은 결제나 은행 상품도 아닙니다. 대부분의 나라에서 결제, 스테이블코인, 결제 대행은 규제 대상 활동입니다.
- 보안. 개인 키를 웹사이트에 절대 붙여 넣지 마세요. npm 패키지
@wen-community/wen-new-standard는 설치하지 마세요. npm이 악성으로 삭제했습니다. 공식 소스로 빌드하세요.
Wen이 커뮤니티를 위해 전합니다. 자세한 내용은 편집 및 데이터 정책에서.
Wen Open Lab · 로드맵 · 전체 코드 · GitHub의 Wen Program Library





