# JS SDK

### Overview:

JavaScript SDKs provide easy-to-use interfaces for interacting with EVM (Ethereum Virtual Machine) compatible blockchains like X1EcoChain, Ethereum, Polygon, BSC, Avalanche, and others.

If you want to use JavaScript to connect with a blockchain node, it's possible to use vanilla JavaScript but several convenience libraries exist within the ecosystem that make this much easier. With these libraries, developers can write intuitive, one-line methods to initialize JSON-RPC requests (under the hood) that interact with blockchain.

***Note:** This guide contains basic information about libraries and it's not a full guide. More info about libraries could be found in their official documentation.*

### Main Libraries:

{% hint style="info" %}

#### **Ethers.js** (Recommended)

* Modern, lightweight library with TypeScript support
* Promise-based API with async/await support
* Built-in wallet management and contract interaction
  {% endhint %}

{% hint style="info" %}

#### **Web3.js**

* Original Ethereum JavaScript library
* Extensive ecosystem and community support
* Callback and promise-based APIs
  {% endhint %}

{% hint style="info" %}
**Viem**

Next-generation TypeScript-first libraryType-safe contract interactionsOptimized for modern development
{% endhint %}

***

### Quick Example:

Here's a simple example using **Ethers.js** to check an account balance:

```
import { ethers } from 'ethers';

// Connect to network (X1EcoChain Nubica Testnet)
const provider = new ethers.JsonRpcProvider('https://nubica-rpc.x1eco.com');

// Check X1 balance
async function getBalance() {
  const address = '<some address>';
  const balance = await provider.getBalance(address);

  // Convert from wei to X1
  const ethBalance = ethers.formatEther(balance);
  console.log(`Balance: ${ethBalance} X1`);
}

getBalance();

```

### What's next?

* Authorize wallet and try to interact with smart contract
* Handle transactions and events
* Implement error handling

#### Additional Links:

* [Documentation](https://docs.ethers.org/v5/)
* [web3.js - Ethereum JavaScript API — web3.js 1.0.0 documentat…](https://web3js.readthedocs.io/en/v1.10.0/)
* [Viem · TypeScript Interface for Ethereum](https://viem.sh/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://x1ecochain.gitbook.io/x1-ecochain-tech-whitepaper/development-environment/js-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
