near-kit
它能做什么
这项技能为智能体提供 near-kit TypeScript 库的指南。near-kit 用于 NEAR 协议区块链。它适合开发读取区块链数据、调用智能合约或连接钱包的应用的开发者。
适用场景
- ✓当你在编写从 NEAR 合约读取数据的网页或 Node 应用的时候。
- ✓当你需要发送 NEAR 代币,或通过代码调用 NEAR 合约的方法时。
- ✓当你想为应用添加 NEAR 钱包连接或 React hooks 的时候。
技能链接
https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-kit/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我想编写一个 TypeScript 函数,从 NEAR 合约读取代币余额,并显示在我的页面上。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会使用库的简单调用,无需密钥即可读取数据;如需签署并发送交易,则使用你提供的密钥。它还涵盖钱包适配器、密钥处理,以及在沙盒中进行测试。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
near-kit
A TypeScript library for NEAR Protocol with an intuitive, fetch-like API.
Quick Start
import { Near } from "near-kit";
// Read-only (no key needed)
const near = new Near({ network: "testnet" });
const data = await near.view("contract.near", "get_data", { key: "value" });
// With signing capability
const near = new Near({
network: "testnet",
privateKey: "ed25519:...",
defaultSignerId: "alice.testnet",
});
await near.call("contract.near", "method", { arg: "value" });
await near.send("bob.testnet", "1 NEAR");
Import Cheatsheet
// Core
import { Near } from "near-kit";
// Keys
import { generateKey, parseSeedPhrase, generateSeedPhrase } from "near-kit";
import { RotatingKeyStore, InMemoryKeyStore } from "near-kit";
import { FileKeyStore } from "near-kit/keys/file";
import { NativeKeyStore } from "near-kit/keys/native";
// Wallet adapters
import { fromHotConnect, fromWalletSelector } from "near-kit";
// NEP-413 verification
import { verifyNep413Signature } from "near-kit";
// Utilities
import { Amount, Gas, isValidAccountId } from "near-kit";
Core Operations
View Methods (Read-Only, Free)
const result = await near.view("contract.near", "get_data", { key: "value" });
const balance = await near.getBalance("alice.near");
const exists = await near.accountExists("alice.near");
Call Methods (Requires Signing)
await near.call(
"contract.near",
"method",
{ arg: "value" },
{ gas: "30 Tgas", attachedDeposit: "1 NEAR" },
);
Send NEAR Tokens
await near.send("bob.near", "5 NEAR");
Type-Safe Contracts
import type { Contract } from "near-kit";
type MyContract = Contract<{
view: {
get_balance: (args: { account_id: string }) => Promise<string>;
};
call: {
transfer: (args: { to: string; amount: string }) => Promise<void>;
};
}>;
const contract = near.contract<MyContract>("token.near");
// View (no options needed)
await contract.view.get_balance({ account_id: "alice.near" });
// Call (options as second arg)
await contract.call.transfer(
{ to: "bob.near", amount: "10" },
{ attachedDeposit: "1 yocto" },
);
Untyped contract proxy:
const guestbook = near.contract("guestbook.near-examples.testnet");
const total = await guestbook.view.total_messages();
const result = await guestbook.call.add_message(
{ text: "Hello!" },
{ gas: "30 Tgas" },
);
Transaction Builder
Chain multiple actions in a single atomic transaction:
const result = await near
.transaction("alice.near")
.functionCall("counter.near", "increment", {}, { gas: "30 Tgas" })
.transfer("counter.near", "0.001 NEAR")
.send();
For all transaction actions and meta-transactions, see references/transactions.md
Configuration
Backend/Scripts
// Direct private key
const near = new Near({
network: "testnet",
privateKey: "ed25519:...",
defaultSignerId: "alice.testnet",
});
// File-based keystore
import { FileKeyStore } from "near-kit/keys/file";
const near = new Near({
network: "testnet",
keyStore: new FileKeyStore("~/.near-credentials", "testnet"),
});
// High-throughput with rotating keys
import { RotatingKeyStore } from "near-kit";
const near = new Near({
network: "mainnet",
keyStore: new RotatingKeyStore({
"bot.near": ["ed25519:key1...", "ed25519:key2...", "ed25519:key3..."],
}),
});
For all key stores and utilities, see references/keys-and-testing.md
Browser Wallets
import { NearConnector } from "@hot-labs/near-connect";
import { Near, fromHotConnect } from "near-kit";
const connector = new NearConnector({ network: "mainnet" });
connector.on("wallet:signIn", async (event) => {
const near = new Near({
network: "mainnet",
wallet: fromHotConnect(connector),
});
await near.call("contract.near", "method", { arg: "value" });
});
connector.connect();
For HOT Connect and Wallet Selector integration, see references/wallets.md
React Bindings (@near-kit/react)
import { NearProvider, useNear, useView, useCall } from "@near-kit/react";
function App() {
return (
<NearProvider config={{ network: "testnet" }}>
<Counter />
</NearProvider>
);
}
function Counter() {
const { data: count, isLoading } = useView<{}, number>({
contractId
常见问题
读取数据需要私钥吗?
不需要。该技能说明,view 调用只读,无需密钥。
它能帮我在使用真实资金之前进行测试吗?
可以。该技能涵盖在沙盒网络中进行测试。
它支持哪些钱包?
该技能提到 Wallet Selector 和 HOT Connect 适配器,以及 React providers。
详情
作者的原始描述
TypeScript library for NEAR Protocol blockchain interaction. Use this skill when writing code that interacts with NEAR Protocol, including viewing contract data, calling contract methods, sending NEAR tokens, building transactions, creating type-safe contract wrappers, integrating wallets (Wallet Selector, HOT Connect), React hooks and providers (@near-kit/react), managing keys, testing with sandbox, meta-transactions (NEP-366), and message signing (NEP-413).
热度
- GitHub 星标
- 7.0k
- 排名
- #13655
- 许可证
- —
- 更新时间
- 2026/10/26
评论
- …
同一仓库的更多技能
internet-court
7.0k帮你的智能体安全地向其他 AI 智能体或付费服务付款、雇用或进行交易,并指引它找到合适的专业指南。
genlayer-erc7710-connector
7.0k帮你的智能体把 AI 审核结果与权限系统连接起来,使不合格的审核可以限制或取消智能体的权限。
genlayer-intelligent-contracts
7.0k帮你的智能体定义 AI 裁判的规则、证据和输出,用于检查另一个智能体是否遵循了其授权范围。
x402-erc7710
7.0k帮你的智能体按次为网络服务付款,并设置在权限预算范围内的持续支出。