# rpc

Durianfun lives on Bitkub Chain (KUB Chain). All integration calls go through standard Ethereum JSON-RPC.

## Mainnet

| Field              | Value                        |
| ------------------ | ---------------------------- |
| **Primary RPC**    | `https://rpc.bitkubchain.io` |
| **Chain ID**       | `96` (`0x60`)                |
| **Block time**     | \~5 seconds                  |
| **Block explorer** | `https://www.kubscan.com`    |
| **Currency**       | KUB                          |

## Testnet

| Field        | Value                                |
| ------------ | ------------------------------------ |
| **RPC**      | `https://rpc-testnet.bitkubchain.io` |
| **Chain ID** | `25925` (`0x6545`)                   |
| **Explorer** | `https://testnet.kubscan.com`        |

## Reliability tips

The public Bitkub RPC is open and free, but it's shared infrastructure. For production use, consider:

{% stepper %}
{% step %}

### Use a fallback array

Rotate between multiple RPC URLs automatically if the primary is slow or rate-limiting.

```javascript
import { FallbackProvider, JsonRpcProvider, Network } from "ethers";

const rpcs = [
  "https://rpc.bitkubchain.io",
  // add alternate RPCs if you have them
];

const network = new Network("kub-mainnet", 96);
const providers = rpcs.map(url => new JsonRpcProvider(url, network, { staticNetwork: true }));
const fallback = new FallbackProvider(providers);
```

{% endstep %}

{% step %}

### Cache token list

`factory.getTokens()` returns the complete list. For high-traffic apps, cache it in memory and refresh every 5-10 seconds instead of per request.
{% endstep %}

{% step %}

### Use event logs for historical data

Polling state every few seconds gets expensive. Instead:

* Index `TokenCreated`, `TokensBought`, `TokensSold` events once via `queryFilter`
* Store in your own DB
* Only poll "live" state (`kubRaised`, `graduated`) for the specific token the user is viewing
  {% endstep %}

{% step %}

### Run your own node (for big apps)

If you're serving thousands of users, run your own Bitkub Chain node via geth + JSON-RPC. This is the most reliable + fastest approach at scale.

Check with Bitkub Chain team for node requirements + archive access.
{% endstep %}
{% endstepper %}

## Known RPC limitations

* **Rate limits**: Bitkub's public RPC may throttle under heavy load. Implement retries with exponential backoff.
* **Historical blocks**: The public RPC may not serve archive queries (very old blocks). Use a service that offers archive access if you need full history.
* **WebSocket**: Check current availability — some public RPCs are HTTP-only.

## Retry pattern

```javascript
async function withRetry(fn, attempts = 3) {
  for (let i = 0; i < attempts; i++) {
    try { return await fn(); }
    catch (e) {
      if (i === attempts - 1) throw e;
      await new Promise(r => setTimeout(r, 500 * Math.pow(2, i)));
    }
  }
}

// usage:
const total = await withRetry(() => factory.totalTokens());
```

## RPC health check

Simple ping to check if the RPC is responding:

```bash
curl -X POST https://rpc.bitkubchain.io \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
```

Expected response:

```json
{"jsonrpc":"2.0","id":1,"result":"0x1d9xxxx"}
```

Any non-200 or error response means the RPC is down or rate-limiting you.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://durianandfun.gitbook.io/durianfun/durian-launchpad/integration/rpc.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.
