AvalancheJS
JavaScript library for Avalanche.
AvalancheJS is a JavaScript Library for interfacing with the Avalanche Platform. It is built using TypeScript and intended to support both browser and Node.js. The AvalancheJS library allows you to issue commands to the Avalanche node APIs.
The APIs currently supported by default are:
- Admin API
- Auth API
- AVM API (X-Chain)
- EVM API (C-Chain)
- Health API
- Index API
- Info API
- Keystore API
- Metrics API
- PlatformVM API
- Socket API
We built AvalancheJS with ease of use in mind. With this library, any JavaScript developer is able to interact with a node on the Avalanche Platform who has enabled their API endpoints for the developer's consumption. We keep the library up-to-date with the latest changes in the Avalanche Platform Specification found in the Platform Chain Specification, Exchange Chain (X-Chain) Specification, Contract Chain (C-Chain) Specification.
Using AvalancheJS, developers can:
- Retrieve balances on addresses
- Get UTXOs for addresses
- Build and sign transactions
- Issue signed transactions to the X-Chain, P-Chain, and C-Chain
- Perform cross-chain swaps between the X, P and C chains
- Add Validators and Delegators
- Create Subnets and Blockchains
Requirements
AvalancheJS requires Node.js LTS version 20.11.1 or higher to compile.
Installation
Using the NPM Package
Add AvalancheJS to your project via npm
or yarn
.
For installing via npm
:
For installing via yarn
:
Build from Repository
You can also pull the repo down directly and build it from scratch.
Clone the AvalancheJS repository:
Then build it:
or
This will generate double builds, one is CommonJS, the other one is ESM. The "avalanchejs" file can then be dropped into any project as a pure JavaScript implementation of Avalanche. The "index.js" file can then be dropped into any project as a pure JavaScript implementation of Avalanche. Depending on the project, the ESM or CommonJS file will be used.
Use AvalancheJS in Projects
The AvalancheJS library can be imported into your existing project as follows:
Importing Essentials
Run Scripts
When cloning the AvalancheJS repository, there are several handy examples and utils. Because it is using ECMAScript Modules (ESM), and not CommonJS, the following command needs to be ran:
This command tells Node.js to use the ts-node/esm loader when running a TypeScript script.
Last updated on