near-api-js
>-
git clone --depth 1 https://github.com/internet-court/internet-court-skill /tmp/near-api-js && cp -r /tmp/near-api-js/vendored/near/near-api-js ~/.claude/skills/near-api-jsSKILL.md
# near-api-js Skill
JavaScript/TypeScript library for NEAR blockchain interaction. Works in browser and Node.js.
## Quick Start
```typescript
import { Account, JsonRpcProvider, KeyPairString } from "near-api-js";
import { NEAR } from "near-api-js/tokens";
// Connect to testnet
const provider = new JsonRpcProvider({ url: "https://test.rpc.fastnear.com" });
// Create account with signer
const account = new Account(
"my-account.testnet",
provider,
"ed25519:..." as KeyPairString,
);
// View call (read-only, via provider)
const data = await provider.callFunction({
contractId: "guestbook.near-examples.testnet",
method: "get_messages",
args: {},
});
// Change call (requires account)
await account.callFunction({
contractId: "guestbook.near-examples.testnet",
methodName: "add_message",
args: { text: "Hello!" },
gas: teraToGas("30"),
deposit: nearToYocto("0.1"),
});
```
## Import Cheatsheet
```typescript
// Core
import { Account, JsonRpcProvider, FailoverRpcProvider } from "near-api-js";
import { KeyPair, PublicKey, KeyType, KeyPairString } from "near-api-js";
// Signers
import { KeyPairSigner, MultiKeySigner, Signer } from "near-api-js";
// Units
import { nearToYocto, yoctoToNear, teraToGas, gigaToGas } from "near-api-js";
// Tokens
import { NEAR, FungibleToken } from "near-api-js/tokens";
import { USDC, wNEAR } from "near-api-js/tokens/mainnet";
import { USDT } from "near-api-js/tokens/testnet";
// Seed phrases
import { generateSeedPhrase, parseSeedPhrase } from "near-api-js/seed-phrase";
// Transactions
import { createTransaction, signTransaction, actions } from "near-api-js";
// Contract with ABI
import { Contract } from "near-api-js";
// Transform key into implicit account ID
import { keyToImplicitAddress } from "near-api-js";
// NEP-413 signing & verification
import { verifyMessage, signMessage } from "near-api-js/nep413";
import {
RpcError,
RpcMethodNotFoundError,
RpcRequestParseError,
ContractMethodNotFoundError,
AccountDoesNotExistError,
// and many more
} from "near-api-js/rpc-errors";
```
## Core Modules
### Account
Main class for account operations.
```typescript
// With signer (can sign transactions)
const account = new Account(accountId, provider, privateKey);
// Without signer (read-only, can add signer later)
const account = new Account(accountId, provider);
// Add signer later
const signer = KeyPairSigner.fromSecretKey(privateKey);
account.setSigner(signer);
// Get state
const state = await account.getState(); // { balance: { total, available, locked }, storageUsage }
// Get balance (with optional token parameter)
const balance = await account.getBalance(); // NEAR balance
const balance = await account.getBalance(USDC); // FT balance
// Transfer NEAR
await account.transfer({
receiverId: "bob.testnet",
amount: NEAR.toUnits("0.1"),
token: NEAR,
});
// Transfer USDC
await account.transfer({
receiverId: "bob.testnet",
amount: USDC.toUnits("0.1"),
token: USDC,
});
// Call contract
await account.callFunction({
contractId: "contract.testnet",
methodName: "set_greeting",
args: { message: "Hello" },
deposit: nearToYocto("0"),
gas: teraToGas("30"),
});
// Sign and send transaction with multiple actions
await account.signAndSendTransaction({
receiverId: "contract.testnet",
actions: [
actions.functionCall(
"method",
{ arg: "value" },
teraToGas("30"),
nearToYocto("0"),
),
actions.transfer(nearToYocto("1")),
],
});
```
### Account Management
```typescript
// Add full access key
await account.addFullAccessKey(
keyPair.getPublicKey(), // or string "ed25519:2ASWc..."
);
// Add function call access key
await account.addFunctionCallAccessKey({
publicKey: keyPair.getPublicKey(), // or string "ed25519:2ASWc..."
contractId: "contract.testnet",
methodNames: ["example_method"],
allowance: nearToYocto("0.25"), // use "0" for unlimited
});
// Delete key
await account.deleteKey(keyPair.getPublicKey()); // or string "ed25519:2ASWc..."
// Delete account and transfer remaining NEAR tokens to beneficiary (FTs and NFTs must be transferred manually before deleting account)
await account.deleteAccount("beneficiary.testnet");
```
### Provider
RPC client for querying blockchain.
```typescript
const provider = new JsonRpcProvider({ url: "https://rpc.mainnet.near.org" });
// Failover provider
const failover = new FailoverRpcProvider([
new JsonRpcProvider({ url: "https://rpc.mainnet.near.org" }),
new JsonRpcProvider({ url: "https://free.rpc.fastnear.com" }),
new JsonRpcProvider({ url: "https://rpc.mainnet.near.org" }),
]);
// Query methods
await provider.viewAccount({ accountId: "alice.near" });
await provider.viewAccessKey({
accountId: "alice.near",
publicKey: keyPair.getPublicKey(), // or string "ed25519:2ASWc..."
});
await provider.viewAccessKeyList({ accountId: "alice.near" });
// read-only call to contract method
await provider.callFunction({
contractId: "contract.testnet",
method: "get_greeting",
args: {},
});
await provider.viewBlock({ finality: "final" });
await provider.sendTransaction(signedTx);
```
### Signers
```typescript
import { KeyPairSigner, MultiKeySigner } from "near-api-js";
// signer shouldn't be used directly for most use cases, instead it's used internally by Account class
const signer = KeyPairSigner.fromSecretKey(privateKey); // or "new KeyPairSigner(keyPair)"
const account = new Account(accountId, provider, signer);
```
### Contract (with ABI)
```typescript
import { Contract, AbiRoot } from "near-api-js";
// ABI definition requires "as const" (const assertions), otherwise types won't be inferred correctly
const abi = {
schema_version: "0.4.0",
metadata: {},
body: {
functions: [
{
name: "add_message",
kind: "call",
modifiers: ["payable"],
params: {
serialization_type: "json",
args: [
{
name: "text",
type_schema: {0G Compute Network guide for decentralized AI inference, fine-tuning, and GPU services. Covers chatbots, image generation, speech-to-text, SDK integration (0g-serving-broker), processResponse API, broker.inference methods, CLI commands (0g-compute-cli), and account management. Use this skill for any 0G compute, 0G AI, or decentralized GPU question.
Give the AI agent its own EVM wallet with admin-controlled policies the agent CANNOT bypass even under prompt injection. Encrypted keystore (AES-256-GCM, scrypt KDF), policy file the agent has no tool to write, deterministic policy gate on every signing operation, optional local HTTP dashboard. Triggers: agent wallet, give the agent a wallet, agent address, fund the agent, agent autonomy, policy gate, kill switch, agent permissions, bounded autonomy, ERC-4337 alternative, session-key alternative.
Crypto wallet operations via the awal CLI — sign in, check balances, send USDC/ETH/POL/SOL, trade tokens, fund the wallet, and use the x402 payment protocol to discover paid services, pay for API calls, monetize an API, or query onchain data. Use whenever the user mentions signing in, login, authentication, wallet status, balance, address, sending money, paying someone, transferring tokens, ENS names, swapping/trading/converting tokens, funding/topping up/onramp, USDC, ETH, POL, SOL, the x402 bazaar, paid APIs, monetizing an endpoint, or querying onchain data on Base.
Help developers write code that interacts with Alkahest escrow contracts using the TypeScript, Rust, or Python SDK
Interact with Alkahest escrow contracts as a buyer, seller, or oracle using the CLI
Use this skill when the user asks to list, create, inspect, update, disable, re-enable, or revoke AltLLM Portal API keys for external agents or applications. Do NOT use for wallet login, billing history, or payment links.
Use this skill when the user asks to log in or out with a wallet session, fetch a wallet sign-in challenge, verify an externally signed challenge, or troubleshoot AltLLM Portal wallet login for the local altllm CLI. Do NOT use for API key management, billing history, or payment links.
Use this skill when the user asks to inspect AltLLM Portal balance, redeem a promo code, review billing transactions, or view usage analytics by period, model, or API key using the local altllm CLI. Do NOT use for API key lifecycle management or payment-link execution.