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

# Installation & Initialization

> Install the RWA SDK from npm and set up a TypeScript or JavaScript project. Covers dependencies, source files, scripts, and environment setup.

Install the RWA SDK from npm and set up your project.

## Set up TS ENV

### 1. New Project

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
npm init -y
npm pkg set type=module
```

### 2. Install packages

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
npm install @peaq-network/rwa
npm i -D typescript tsx @types/node
npm i dotenv
```

### 3. Add a TypeScript config

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
touch tsconfig.json
```

Add the following into the file:

```json theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "verbatimModuleSyntax": true,
    "sourceMap": true,
    "noEmit": true
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", "dist"]
}
```

### 4. Update scripts in `package.json`.

The `src/index.ts` is the executable file.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
    "scripts": {
        "dev": "tsx watch src/index.ts",
        "start": "tsx src/index.ts",
        "typecheck": "tsc -p tsconfig.json --noEmit"
    },
```

### 5. Create source file

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
mkdir src
touch src/index.ts
```

## Set up JS ENV

### 1. Initialize node env

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
npm init -y
npm pkg set type=module
```

### 2. Install packages

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
npm install @peaq-network/rwa
npm i dotenv
```

### 3. Create source file

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
mkdir src
touch src/index.js
```

## Execute

For both TS/JS environments your next steps are:

### Create .env file

The examples read secrets from a `.env` file. Create it together with a `.gitignore` so you do not commit keys:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
touch .env
touch .gitignore
```

To follow the full walkthrough, define `.env` as:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
HTTPS_BASE_URL="https://peaq-agung.api.onfinality.io/public"

# peaq owner admin
ADMIN_PUBLIC_ADDRESS=""
ADMIN_PRIVATE_KEY=""

# Claim Issuer
CLAIM_ISSUER_PUBLIC_ADDRESS=""
CLAIM_ISSUER_PRIVATE_KEY=""
CLAIM_ISSUER_CONTRACT_ADDRESS=""
CLAIM_ISSUER_IDENTITY_ADDRESS=""

# Machine Regulator
MACHINE_REGULATOR_PUBLIC_ADDRESS=""
MACHINE_REGULATOR_PRIVATE_KEY=""

# Machine Issuer
MACHINE_ISSUER_PUBLIC_ADDRESS=""
MACHINE_ISSUER_PRIVATE_KEY=""
# Machine NFT contract created for this issuer by addMachineIssuer
MACHINE_NFT_ADDRESS=""

# Alice
ALICE_PUBLIC_ADDRESS=""
ALICE_PRIVATE_KEY=""

# Bob
BOB_PUBLIC_ADDRESS=""
BOB_PRIVATE_KEY=""

# Charlie
CHARLIE_PUBLIC_ADDRESS=""
CHARLIE_PRIVATE_KEY=""
```

`HTTPS_BASE_URL` is the EVM RPC for the chain you pass as `chainId`. The examples use agung; for `Chain.PEAQ` use a peaq mainnet RPC such as `https://quicknode1.peaq.xyz`.

Add to `.gitignore`:

```
.env
```

### TS Execution

Copy one of the examples with the proper authority into `src/index.ts` for execution and run with:

```
npm start
```

### JS Execution

Copy one of the examples with the proper authority into `src/index.js` for execution and run with:

```
node src/index.js
```

## `new RWA(opts)`

Initialize the peaq RWA SDK for a specific chain. The instance wires module addresses for that chain and exposes module entry points. A Provider is required at initialization and is used for read operations; write operations require an explicit Signer.

### Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| **chainId** | `Chain` | Required | Target network: `Chain.AGUNG` (9990) for development and testing, or `Chain.PEAQ` (3338). On peaq mainnet the framework has no trusted Claim Issuers or Machine Regulators configured yet, so KYC-gated calls revert there. |
| **provider** | `Provider` | Required | An ethers Provider used for read-only calls across modules. |

### Usage

#### TypeScript

```Typescript theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import 'dotenv/config';
import { RWA, Chain, type SDKInit } from '@peaq-network/rwa';
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL!);
const init: SDKInit = { chainId: Chain.AGUNG, provider: provider };
const rwa_sdk = new RWA(init);
console.log(rwa_sdk);
```

#### JavaScript (ESM)

```js theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
import 'dotenv/config';
import { RWA, Chain } from "@peaq-network/rwa";
import { JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider: provider });
console.log(rwa_sdk);
```

#### JavaScript (CommonJS)

Optional setup to use **cjs**. Remove `"type": "module",` from your `package.json`.

```js theme={"theme":{"light":"github-light-default","dark":"github-dark"}}
require('dotenv').config();
const { RWA, Chain } = require('@peaq-network/rwa');
const { JsonRpcProvider } = require('ethers');

const provider = new JsonRpcProvider(process.env.HTTPS_BASE_URL);
const rwa_sdk = new RWA({ chainId: Chain.AGUNG, provider: provider });
console.log(rwa_sdk);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.