Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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).
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 59% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 45% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 83% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 7% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 12% | 0% |
A TypeScript library for NEAR Protocol with an intuitive, fetch-like API.
typescriptimport { 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");
typescript// 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";
typescriptconst result = await near.view("contract.near", "get_data", { key: "value" }); const balance = await near.getBalance("alice.near"); const exists = await near.accountExists("alice.near");
typescriptawait near.call( "contract.near", "method", { arg: "value" }, { gas: "30 Tgas", attachedDeposit: "1 NEAR" }, );
typescriptawait near.send("bob.near", "5 NEAR");
typescriptimport 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:
typescriptconst 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" }, );
Chain multiple actions in a single atomic transaction:
typescriptconst 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
typescript// 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
typescriptimport { 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
tsximport { 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: "counter.testnet", method: "get_count", }); const { mutate: increment, isPending } = useCall({ contractId: "counter.testnet", method: "increment", }); if (isLoading) return <div>Loading...</div>; return ( <button onClick={() => increment({})} disabled={isPending}> Count: {count} </button> ); }
For all React hooks, React Query/SWR integration, and SSR patterns, see references/react.md
typescriptimport { Near } from "near-kit"; import { Sandbox } from "near-kit/sandbox"; const sandbox = await Sandbox.start(); const near = new Near({ network: sandbox }); const testAccount = `test-${Date.now()}.${sandbox.rootAccount.id}`; await near .transaction(sandbox.rootAccount.id) .createAccount(testAccount) .transfer(testAccount, "10 NEAR") .send(); await sandbox.stop();
For sandbox patterns and Vitest integration, see references/keys-and-testing.md
typescriptimport { InsufficientBalanceError, FunctionCallError, NetworkError, TimeoutError, } from "near-kit"; try { await near.call("contract.near", "method", {}); } catch (error) { if (error instanceof InsufficientBalanceError) { console.log(`Need ${error.required}, have ${error.available}`); } else if (error instanceof FunctionCallError) { console.log(`Panic: ${error.panic}`, `Logs: ${error.logs}`); } }
All amounts accept human-readable formats:
typescript"10 NEAR"; // 10 NEAR "10"; // 10 NEAR 10; // 10 NEAR ("30 Tgas"); // 30 trillion gas units
Programmatic formatting:
typescriptimport { Amount, Gas } from "near-kit"; Amount.NEAR(0.1); Amount.yocto(1000n); Amount.parse("5 NEAR"); Gas.parse("30 Tgas");
typescriptimport { generateKey, generateSeedPhrase, parseSeedPhrase, isValidAccountId, } from "near-kit"; // Generate new keypair const key = generateKey(); // key.publicKey, key.secretKey // generateSeedPhrase() returns a string (just the phrase) const seedPhrase = generateSeedPhrase(); // "word1 word2 word3 ... word12" // parseSeedPhrase() returns a KeyPair-like object const keyPair = parseSeedPhrase("word1 word2 ... word12"); // keyPair.publicKey, keyPair.secretKey // Validation isValidAccountId("alice.near"); // true
typescriptimport { Near, verifyNep413Signature } from "near-kit"; const near = new Near({ network: "testnet" }); const isValid = await verifyNep413Signature( signedMessage, { message: "log me in", recipient: "myapp.com", nonce: challengeBuffer }, { near, maxAge: Infinity }, );
For detailed documentation on specific topics:
Other measured skills in the registry, with their headline benchmark lift.