Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions website/docs/xdcchain/developers/explorers/advanced-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: Advanced Features
---

## Advanced Features

### Event Log Decoding

Event logs are emitted by smart contracts during transaction execution. The explorer decodes these logs when the contract is verified, displaying human-readable event names and parameters.

**Viewing Event Logs:**

1. Navigate to a transaction detail page
2. Scroll to the **Logs** section
3. View decoded event names (e.g., `Transfer`, `Approval`)
4. Expand individual logs to see parameter names and values

**Topics Structure:**

- **Topic 0:** Event signature hash (keccak256 of event definition)
- **Topic 1-3:** Indexed parameters (up to 3)
- **Data:** Non-indexed parameters (ABI-encoded)

**Example Transfer Event:**

```solidity
event Transfer(address indexed from, address indexed to, uint256 value);
```

Decoded display:

- Topic 0: `0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef`
- Topic 1 (from): `0x000...0001234...abcd`
- Topic 2 (to): `0x000...0005678...efgh`
- Data (value): `1000000000000000000`

### Internal Transactions

Internal transactions are value transfers and contract calls triggered by external transactions. They are not recorded as separate transactions on the blockchain but can be traced through execution.

**Accessing Internal Transactions:**

1. Open a transaction detail page
2. Click the **Internal Transactions** tab
3. View the call trace showing:
- Call depth and type (CALL, DELEGATECALL, STATICCALL)
- From and to addresses
- Value transferred
- Gas used by each internal call

**Use Cases:**

- Tracking multi-hop transfers
- Debugging contract interactions
- Analyzing DeFi protocol flows
- Verifying token swap paths

### Gas Tracker

The gas tracker provides real-time and historical gas price data, helping users optimize transaction costs.

**Metrics Available:**

- **Safe Gas Price:** Confirmed within expected time
- **Propose Gas Price:** Standard confirmation speed
- **Fast Gas Price:** Priority confirmation
- **Average Block Time:** Current network block interval
- **Average Gas Limit:** Typical block capacity

**Historical Gas Charts:**

View gas price trends over time to identify optimal transaction windows and network congestion patterns.

### Analytics Dashboard

The explorer provides network-wide analytics for macro-level blockchain analysis.

**Available Charts:**

- Daily transaction count
- Active address count
- XDC transfer volume
- Smart contract deployments
- Validator performance metrics
- Token transfer volume by category

**Export Options:**

Most charts support CSV export for custom analysis in spreadsheet or data science tools.

---

249 changes: 249 additions & 0 deletions website/docs/xdcchain/developers/explorers/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
---
title: Example usage
---

## API Documentation

Both XDCScan and Apothem Explorer provide REST APIs for programmatic access to blockchain data. The API enables integration with wallets, dashboards, trading bots, and analytics platforms.

### API Key Setup

**Creating an API Key:**

1. Create an account on XDCScan (registration required)
2. Navigate to **API Keys** in account settings
3. Click **Create API Key**
4. Name your key (e.g., "Production Dashboard")
5. Copy the generated key immediately (shown only once)

**Rate Limits:**

| Plan | Requests per Second | Daily Limit |
|------|---------------------|-------------|
| Free | 5 | 10,000 |
| Standard | 10 | 100,000 |
| Professional | 25 | 500,000 |
| Enterprise | Custom | Custom |

**Authentication:**

Include the API key as a query parameter:

```
https://xdcscan.io/api?module=account&action=balance&address=xdc1234...&apikey=YourApiKey
```

### Core API Endpoints

#### Account Module

**Get XDC Balance:**

```
GET /api?module=account&action=balance&address={address}&tag=latest&apikey={key}
```

Response:

```json
{
"status": "1",
"message": "OK",
"result": "1000000000000000000"
}
```

**Get Transaction List:**

```
GET /api?module=account&action=txlist&address={address}&startblock=0&endblock=99999999&sort=asc&apikey={key}
```

**Get Token Transfer Events:**

```
GET /api?module=account&action=tokentx&contractaddress={token}&address={holder}&page=1&offset=100&apikey={key}
```

**Get Token Balance:**

```
GET /api?module=account&action=tokenbalance&contractaddress={token}&address={holder}&tag=latest&apikey={key}
```

#### Contract Module

**Get Contract ABI:**

```
GET /api?module=contract&action=getabi&address={contract}&apikey={key}
```

Response:

```json
{
"status": "1",
"message": "OK",
"result": "[{...}]"
}
```

**Get Contract Source Code:**

```
GET /api?module=contract&action=getsourcecode&address={contract}&apikey={key}
```

#### Transaction Module

**Get Transaction Receipt Status:**

```
GET /api?module=transaction&action=gettxreceiptstatus&txhash={hash}&apikey={key}
```

**Get Transaction Status:**

```
GET /api?module=transaction&action=getstatus&txhash={hash}&apikey={key}
```

#### Block Module

**Get Block Reward:**

```
GET /api?module=block&action=getblockreward&blockno={number}&apikey={key}
```

**Get Block Countdown:**

```
GET /api?module=block&action=getblockcountdown&blockno={number}&apikey={key}
```

#### Stats Module

**Get XDC Supply:**

```
GET /api?module=stats&action=xdcsupply&apikey={key}
```

**Get Validators:**

```
GET /api?module=stats&action=validators&apikey={key}
```

### API Response Format

All API responses follow a standard JSON structure:

```json
{
"status": "1",
"message": "OK",
"result": "..."
}
```

**Status Codes:**

| Status | Meaning |
|--------|---------|
| "1" | Success |
| "0" | Error or no data |

**Error Handling:**

```javascript
const response = await fetch(apiUrl);
const data = await response.json();

if (data.status === "0") {
console.error("API Error:", data.message);
// Handle error: rate limit, invalid parameters, etc.
} else {
// Process data.result
}
```

### Python API Client Example

```python
import requests

API_KEY = "YourApiKey"
BASE_URL = "https://xdcscan.io/api"

def get_balance(address):
params = {
"module": "account",
"action": "balance",
"address": address,
"tag": "latest",
"apikey": API_KEY
}
response = requests.get(BASE_URL, params=params)
data = response.json()

if data["status"] == "1":
# Convert wei to XDC
balance_xdc = int(data["result"]) / 10**18
return balance_xdc
else:
raise Exception(f"API Error: {data['message']}")

# Example usage
address = "xdc1234567890abcdef1234567890abcdef12345678"
balance = get_balance(address)
print(f"Balance: {balance} XDC")
```

### JavaScript API Client Example

```javascript
const API_KEY = "YourApiKey";
const BASE_URL = "https://xdcscan.io/api";

async function getTransactions(address, page = 1, offset = 10) {
const params = new URLSearchParams({
module: "account",
action: "txlist",
address: address,
startblock: "0",
endblock: "99999999",
page: page.toString(),
offset: offset.toString(),
sort: "desc",
apikey: API_KEY
});

const response = await fetch(`${BASE_URL}?${params}`);
const data = await response.json();

if (data.status === "1") {
return data.result.map(tx => ({
hash: tx.hash,
from: tx.from,
to: tx.to,
value: parseInt(tx.value) / 1e18,
timestamp: new Date(parseInt(tx.timeStamp) * 1000),
gasUsed: tx.gasUsed,
status: tx.txreceipt_status === "1" ? "Success" : "Failed"
}));
} else {
throw new Error(data.message);
}
}

// Example usage
getTransactions("xdc1234...abcd", 1, 5)
.then(txs => console.log(txs))
.catch(err => console.error(err));
```

---

Loading