用途:帮助开发者构建 NEAR Protocol dApp,覆盖新建项目与为现有项目添加钱包连接两类任务。
主要能力与用法: 新建项目:运行 npx create-near-app@latest,或带参数 npx create-near-app my-app --frontend vite-react --contract rs --install。前端框架可选 vite-react、next-app、next-page;合约语言可选 rs(Rust)或 ts(TypeScript)。
现有 React 项目接入钱包:安装 npm install near-connect-hooks @hot-labs/near-connect near-api-js,用 NearProvider 包裹应用根节点并配置 network,例如 mainnet;在组件中使用 useNearWallet 获取 signedAccountId、signIn、signOut、viewFunction、callFunction。
非 React 或原生 JS:直接使用 @hot-labs/near-connect,安装 npm install @hot-labs/near-connect,创建 NearConnector 并监听 wallet:signIn 事件,再调用 connect()。
常见模式:读取合约状态无需钱包,使用 viewFunction({ contractId, method, args });写入合约需要钱包,使用 callFunction({ contractId, method, args, deposit });转账使用 transfer({ receiverId, amount });NEAR 与 yoctoNEAR 换算使用 near-api-js 的 nearToYocto() / yoctoToNear(),1 NEAR 等于 1000000000000000000000000 yoctoNEAR;默认 gas 为 30000000000000(30 TGas)。
适用场景:需要快速搭建 NEAR dApp 脚手架,或在 React、非 React 前端中集成 NEAR 钱包登录、合约读写与转账。
限制:资料未提供收费、价格、平台支持范围、性能效果等细节;具体模板与参数以 create-near-app --help 为准。