Saltar al contenido
Skillpedia
APIs y servidores (backend)7,0 mil · #13652

near-api-js

Qué hace

Esta skill es una guía para desarrolladores de near-api-js versión 7, la biblioteca de JavaScript para comunicarse con la cadena de bloques de NEAR. Cubre la conexión a la red, la gestión de cuentas y claves, las llamadas a contratos y el manejo de tokens fungibles y NFT, y funciona en navegadores y en Node.js.

Cuándo usarla

  • ✓Cuando creas una app web o de Node.js que se comunica con la cadena de bloques de NEAR.
  • ✓Cuando necesitas firmar transacciones o llamar a un contrato inteligente de NEAR desde código.
  • ✓Cuando quieres trabajar con tokens fungibles o NFT en NEAR.

Link de la skill

https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-api-js/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-api-js/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Quiero que mi script de Node.js lea mensajes de un contrato de libro de visitas de NEAR y añada uno nuevo.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

El agente usa el proveedor de la biblioteca para leer datos de contrato, y una cuenta con clave de firma para enviar cambios. Incluye funciones auxiliares para importes, como convertir NEAR a yoctoNEAR, y funciones auxiliares para tokens habituales.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

near-api-js Skill

JavaScript/TypeScript library for NEAR blockchain interaction. Works in browser and Node.js.

Quick Start

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

// 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.

// 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

// 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.

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
Preguntas frecuentes

¿Funciona en el navegador y en Node.js?

Sí. La biblioteca funciona en ambos.

¿Cuál es la diferencia entre una llamada de vista y una de cambio?

Una llamada de vista lee datos sin firma, mientras que una de cambio envía una transacción firmada.

¿Qué versión cubre esta guía?

Cubre near-api-js versión 7.

Detalles

Descripción original del autor

Guide for developing with near-api-js v7 - the JavaScript/TypeScript library for NEAR blockchain interaction. Use when: (1) building apps that interact with NEAR blockchain, (2) creating/signing transactions, (3) calling smart contracts, (4) managing accounts and keys, (5) working with NEAR RPC API, (6) handling FT/NFT tokens on NEAR, (7) using NEAR cryptographic operations (KeyPair, signing), (8) converting between NEAR units (yocto, gas), (9) gasless/meta transactions with relayers, (10) NEP-413 message signing for authentication, (11) storage deposit management for FT contracts. Triggers on

repo: internet-court/internet-court-skill

Popularidad

Estrellas en GitHub
7,0 mil
Posición en el ranking
#13652
Licencia
—
Actualizada
26/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas