> For the complete documentation index, see [llms.txt](https://x1ecochain.gitbook.io/x1-ecochain-tech-whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://x1ecochain.gitbook.io/x1-ecochain-tech-whitepaper/development-environment/js-sdk.md).

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