> ## Documentation Index
> Fetch the complete documentation index at: https://docs.therootnetwork.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Install Native API

## @therootnetwork/api

A utility package that complements the [`@polkadot/api`](https://www.npmjs.com/package/@polkadot/api) to connect and interact with the Root Network node.

## Install

```ts
yarn add @polkadot/api @therootnetwork/api
yarn add -D @therootnetwork/api-types # optional, for Typescript support
```

## Usage

1. Create an API instance

```ts
import "@therootnetwork/api-types"; // optional, for Typescript support
import { ApiPromise } from "@polkadot/api";
import { getApiOptions, getPublicProvider } from "@therootnetwork/api";

const api = await ApiPromise.create({
  ...getApiOptions(),
  ...getPublicProvider("root"),
});
```

1. Use `api` instance to interact with node

```ts
// query and display account data
const data = await api.query.system.account("0xE04CC55ebEE1cBCE552f250e85c57B70B2E2625b");
console.log(data.toHuman());
```

## API

### `function getApiOptions()`

Returns an `ApiOptions` object that contains necessary types and RPC methods to connect The Root Network.

### `function getPublicProvider(network: NetworkName, useWsProvider?: boolean)`

Returns a `provider` instance of either `WsProvider` or `HttpProvider` that connects to TRN mainnet `"root"` or testnet `"porcini"`.
