Wen Open Lab · 开放集成

第 6 阶段:Devnet——亲自复现可直接运行

English · Italiano · 中文 · 한국어

由 Wen 与 AI 一起从英文译出。以英文页面为准;欢迎指正。

在 Solana devnet 上测试 Wen
公开测试,而非纸上谈兵

本地测试证明逻辑,公共网络则向所有人证明。Devnet 是 Solana 的开放测试网:程序与主网相同,但币没有价值。本页是一份可重复的配方。运行一次也好,运行一百次也好——每次运行都会生成任何人都能在浏览器中打开的新地址。

为什么 devnet 很重要

核验记录显示有 41 项检查在 LiteSVM(Solana 运行时的本地副本)中通过。这是有力的证据,但只发生在一台机器上。devnet 运行把同样的模型搬到公共网络上,每笔交易都有公开链接。没有人需要相信我们:打开链接,就能看到供应量为一的收据、带备注的发票付款,以及没有备注而被拒绝的付款。

你需要什么

  • Node.js 20 或更新版本,以及 lab/code 中的文件。
  • Solana 命令行工具(solana、solana-keygen)。
  • 一个只为 devnet 创建的全新空钱包。绝不要使用存有真实资金的钱包。

复现:五条命令

# 1. install the example project
npm install

# 2. create a throwaway devnet wallet (it never holds real money)
solana-keygen new -o devnet-wallet.json --no-bip39-passphrase

# 3. get free devnet SOL (test coins with no value; use faucet.solana.com if the CLI is rate-limited)
solana airdrop 2 $(solana-keygen pubkey devnet-wallet.json) --url devnet

# 4. run the local checks first
npm test

# 5. run the public devnet demo
KEYPAIR=./devnet-wallet.json npm run devnet

脚本拒绝在 devnet 以外的任何网络上运行,如果钱包里的 devnet SOL 少于 0.2,也会停止。

脚本做什么

  1. 模型 1:为一位新的测试买家铸造一张灵魂绑定收据 NFT,订单哈希和保修日期都在铸币内,然后把供应量锁定为一。
  2. 模型 3:创建一种手续费 0.25%、上限 50 个单位、账户默认冻结的结算代币,开设买方和卖方账户(卖方要求发票备注),批准双方,为买方注资,支付发票 INV-DEVNET-0001,然后尝试一笔没有发票号的付款,并展示它被拒绝。
  3. 为每笔交易和每个地址打印浏览器链接。

文件:lab/code/scripts/devnet-demo.ts · Apache-2.0

// Wen Open Lab: run Models 1 and 3 on PUBLIC DEVNET and print explorer links anyone can open.
// Devnet only. Use a NEW, EMPTY wallet created just for this. No real funds are ever needed.
// License: Apache-2.0. Example code, not audited.
//
//   solana-keygen new -o devnet-wallet.json          # new throwaway wallet
//   solana airdrop 2 $(solana-keygen pubkey devnet-wallet.json) --url devnet
//   KEYPAIR=./devnet-wallet.json npx tsx scripts/devnet-demo.ts
import { Keypair, LAMPORTS_PER_SOL, Transaction, sendAndConfirmTransaction, type TransactionInstruction } from '@solana/web3.js';
import { TOKEN_2022_PROGRAM_ID, createMintToInstruction } from '@solana/spl-token';
import { getConnection, loadKeypair } from '../src/common.js';
import { buildReceiptInstructions, receiptLayout, type Order } from '../src/01-receipt-nft.js';
import {
  buildApproveCounterparty, buildInvoiceAccount, buildPayInvoice, buildSettlementMint,
  invoiceAccountSpace, settlementMintSpace, DECIMALS,
} from '../src/03-b2b-invoice.js';

const connection = getConnection();
const wallet = loadKeypair();
const link = (kind: 'tx' | 'address', id: string) => `https://explorer.solana.com/${kind}/${id}?cluster=devnet`;

async function send(label: string, ixs: TransactionInstruction[], signers: Keypair[]) {
  const sig = await sendAndConfirmTransaction(connection, new Transaction().add(...ixs), signers);
  console.log(`  ${label}\n    ${link('tx', sig)}`);
  return sig;
}

async function main() {
  const endpoint = (connection as unknown as { rpcEndpoint: string }).rpcEndpoint;
  if (!/devnet/.test(endpoint)) throw new Error(`Refusing to run outside devnet: ${endpoint}`);
  const balance = await connection.getBalance(wallet.publicKey);
  console.log(`Wallet ${wallet.publicKey.toBase58()} has ${balance / LAMPORTS_PER_SOL} devnet SOL`);
  if (balance < 0.2 * LAMPORTS_PER_SOL) throw new Error('Need at least 0.2 devnet SOL: run `solana airdrop 2 <address> --url devnet`');

  // ---- Model 1: receipt NFT (soulbound) to a fresh "buyer" address ----
  console.log('\nModel 1 — receipt and warranty NFT');
  const buyer = Keypair.generate();
  const mint = Keypair.generate();
  const order: Order = { orderId: `DEVNET-${Date.now()}`, sku: 'WEN-PLUSH-01', priceMinorUnits: 2500, currency: 'USD', purchasedAt: new Date().toISOString(), warrantyMonths: 12 };
  const opts = { soulbound: true, uri: 'https://wen-watt.github.io/lab/receipt-warranty-wns.html' };
  const { rentSpace } = receiptLayout(order, mint.publicKey, wallet.publicKey, opts);
  const rent = await connection.getMinimumBalanceForRentExemption(rentSpace);
  const { instructions, buyerAta } = buildReceiptInstructions({ order, mint: mint.publicKey, merchant: wallet.publicKey, buyer: buyer.publicKey, opts, rentLamports: rent });
  await send('receipt minted, supply locked at 1', instructions, [wallet, mint]);
  console.log(`    receipt mint: ${link('address', mint.publicKey.toBase58())}`);
  console.log(`    buyer holds it in: ${link('address', buyerAta.toBase58())}`);

  // ---- Model 3: B2B settlement token with fee, allowlist and invoice memo ----
  console.log('\nModel 3 — B2B invoice settlement');
  const settle = Keypair.generate();
  await send('settlement mint created (fee 0.25% cap 50, frozen by default)',
    buildSettlementMint(wallet.publicKey, settle.publicKey, await connection.getMinimumBalanceForRentExemption(settlementMintSpace())), [wallet, settle]);
  const accRent = await connection.getMinimumBalanceForRentExemption(invoiceAccountSpace());
  const payerAcc = Keypair.generate(), sellerAcc = Keypair.generate();
  // In this demo one wallet plays both companies; in real life they are different owners.
  await send('buyer account opened', buildInvoiceAccount(wallet.publicKey, payerAcc.publicKey, settle.publicKey, accRent, false), [wallet, payerAcc]);
  await send('seller account opened (invoice memo required)', buildInvoiceAccount(wallet.publicKey, sellerAcc.publicKey, settle.publicKey, accRent, true), [wallet, sellerAcc]);
  await send('both companies approved by the issuer', [
    ...buildApproveCounterparty(wallet.publicKey, settle.publicKey, payerAcc.publicKey),
    ...buildApproveCounterparty(wallet.publicKey, settle.publicKey, sellerAcc.publicKey),
  ], [wallet]);
  const unit = 10n ** BigInt(DECIMALS);
  await send('buyer funded with 10,000 test units', [createMintToInstruction(settle.publicKey, payerAcc.publicKey, wallet.publicKey, 10_000n * unit, [], TOKEN_2022_PROGRAM_ID)], [wallet]);
  await send('invoice INV-DEVNET-0001 paid: 1,000 units, memo on-chain',
    buildPayInvoice({ mint: settle.publicKey, from: payerAcc.publicKey, to: sellerAcc.publicKey, payer: wallet.publicKey, invoiceId: 'INV-DEVNET-0001', amount: 1_000n * unit }), [wallet]);

  try {
    await send('payment WITHOUT invoice number (must fail)',
      buildPayInvoice({ mint: settle.publicKey, from: payerAcc.publicKey, to: sellerAcc.publicKey, payer: wallet.publicKey, invoiceId: null, amount: 1n * unit }), [wallet]);
    console.log('  !! unexpected: payment without memo succeeded');
  } catch {
    console.log('  payment WITHOUT invoice number was rejected, as designed');
  }
  console.log(`    settlement mint: ${link('address', settle.publicKey.toBase58())}`);
  console.log('\nDone. Paste these links into the Lab devnet page so anyone can inspect them.');
}

main().catch(e => { console.error(e); process.exit(1); });

已公布的运行

运行日期收据铸币结算铸币发票付款
#1待定——首次公开运行将连同浏览器链接在此公布

自己运行过了?在 X 上与社区分享你的链接(@wenwencoin)。独立运行是最好的证明。整个运行过程已用四种语言(含中文)写成文章:dev.to 上的开发者版和Hashnode 上的大众版。

安全规则

  • devnet 币没有价值,也不能出售。任何声称“出售” devnet SOL 的人都是骗局。
  • 不要把 devnet-wallet.json 放进任何代码仓库,也绝不要在主网上重复使用。
  • devnet 有时会被重置或变慢;如果某一步失败,稍等再运行——每次运行都是全新开始。

图说 Wen

Wen 在 Seeker 上的 devnet 运行
你自己的运行,你自己的证明
Wen 猫查看浏览器
每一步都有链接
建设者 Wen 复现测试
随时复现
手机上的 Wen,devnet 链接
分享链接
devnet 上的 Wen 开发者
欢迎建设者

Wen 在此模型中的位置

真正的 WEN 代币只存在于主网;devnet 上没有 WEN。因此脚本会创建自己的测试代币,并清楚标明是测试。当一个模型准备好用于 WEN——例如第 7 阶段,用 WEN 支付、收到 USDC——它只有在完成 devnet 运行和独立审查后才会上主网。

Wen 的主线:一个合约,处处可见

实验室的每个模型都免费且开放,并带着同一个签名:$WEN 代币合约。复制它,在你自己的文档中重复它,使用前务必在浏览器上核验。

WENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk

核验:Solana Explorer · 如何找到合约 ID

开放使用政策

  • 免费且开放。实验室的全部代码以 Apache License 2.0 发布,与 Wen Program Library 相同。无论是否商用,都可以使用、修改、发布;请保留许可声明。
  • 只用开放工具。基于公开且有文档的工具构建: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

Wen 在地球上空太空行走,系着安全绳修理飞船外壳
系着安全绳练习:只用 devnet,一个全新的空钱包,真实的链,零风险。