EOSJS is the official JavaScript library for interacting with EOSIO blockchain APIs. It provides a comprehensive set of tools for sending transactions, querying blockchain state, managing accounts, and performing cryptographic operations like signing and verifying. The current stable version is 22.1.0, which introduces support for read-only transactions within smart contracts via HTTP-RPC and action return values. Historically, the library has undergone significant internal changes, such as the switch from `eosjs-ecc` to the `elliptic` cryptography library in v21.0.2, while striving to maintain a stable public API. Releases often include security, stability, and miscellaneous fixes, with release candidates preceding major version bumps. It is a critical component for building applications that interact with EOSIO-based blockchains, offering robust TypeScript support and keeping pace with new blockchain features.
npm install eosjsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize `eosjs` with `JsonRpc` and `Api`, perform a read-only query using `get_table_rows`, and provides a commented-out example of pushing a transaction.
Review the official EOSIO API plugin documentation and update your application's code to align with the new endpoints and TypeScript definitions introduced in EOSJS v22.0.0. Pay close attention to any custom API calls.
Ensure your application does not rely on internal details of the previous `eosjs-ecc` library. If you have custom cryptographic handling or key format expectations, thoroughly test for compatibility with the new `elliptic` library. Most users should be unaffected if using only the public API.
For versions 21.0.x, ensure that if you set `shouldHash` to `false`, you are providing data that has already been correctly hashed externally. It is strongly recommended to upgrade to the latest stable version (22.x) to ensure all signing and recovery methods function as expected.
Immediately upgrade to EOSJS v21.0.4 or higher to patch critical security vulnerabilities in the underlying dependencies. This is crucial for application security and supply chain integrity.
Prefer `import` statements and configure your project for ESM usage (e.g., by setting `"type": "module"` in `package.json`). If you must use CommonJS, explore dynamic `import()` or specific transpilation configurations, or consider sticking to older `eosjs` versions that offered better CJS compatibility if full CJS support is critical.
In Node.js, install `node-fetch` (e.g., `npm install node-fetch`) and pass it explicitly: `new JsonRpc(rpcEndpoint, { fetch: require('node-fetch') })` or `new JsonRpc(rpcEndpoint, { fetch })` after `import fetch from 'node-fetch'`.Ensure your `SignatureProvider` (e.g., `JsSignatureProvider`) is correctly initialized with the private key corresponding to the `actor` and `permission` specified in your transaction's `authorization` array. Double-check the private key and account name for accuracy and that the private key corresponds to the network you're connected to.
In Node.js, import `TextEncoder` and `TextDecoder` from the built-in `util` module: `import { TextEncoder, TextDecoder } from 'util';` and pass them to the `Api` constructor: `{ textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }`.Provide an instance of a `SignatureProvider` (e.g., `JsSignatureProvider` for testing purposes, or a more secure provider for production) to the `Api` constructor. If you only need to query blockchain state and do not intend to send transactions, you can use `JsonRpc` directly without `Api`.