blockchain-api
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Blockchain API

A TypeScript library for interacting with the Exatechl2 blockchain.

Installation

npm install blockchain-api

Modular Architecture

This library is built with a modular architecture, making it easy to maintain and extend:

blockchain-api/
├── src/
│   ├── index.ts                  # Main export file
│   ├── config.ts                 # Configuration management
│   ├── types/                    # Type definitions
│   │   ├── index.ts              # Export all types
│   │   ├── block.ts              # Block-related types
│   │   ├── transaction.ts        # Transaction-related types
│   │   ├── address.ts            # Address-related types
│   │   ├── token.ts              # Token-related types
│   │   ├── events.ts             # Event-related types
│   │   └── search.ts             # Search-related types
│   ├── core/                     # Core functionality
│   │   ├── index.ts              # Export core functions
│   │   └── rpc.ts                # Basic RPC functionality
│   ├── modules/                  # Feature modules
│   │   ├── index.ts              # Export all modules
│   │   ├── blocks/               # Block-related functionality
│   │   │   ├── index.ts          # Export block functions
│   │   │   └── blocks.ts         # Block operations
│   │   ├── transactions/         # Transaction-related functionality
│   │   │   ├── index.ts          # Export transaction functions
│   │   │   └── transactions.ts   # Transaction operations
│   │   ├── addresses/            # Address-related functionality
│   │   │   ├── index.ts          # Export address functions
│   │   │   └── addresses.ts      # Address operations
│   │   ├── tokens/               # Token-related functionality
│   │   │   ├── index.ts          # Export token functions
│   │   │   └── tokens.ts         # Token operations
│   │   ├── events/               # Event log functionality
│   │   │   ├── index.ts          # Export event functions
│   │   │   ├── events.ts         # Event log operations
│   │   │   └── README.md         # Event module documentation
│   │   └── search/               # Search functionality
│   │       ├── index.ts          # Export search functions
│   │       └── search.ts         # Search operations
│   └── utils/                    # Utility functions
│       ├── index.ts              # Export utility functions
│       └── formatters.ts         # Data formatting utilities
├── examples/                     # Example scripts
│   ├── basic-usage.ts            # Basic usage examples
│   ├── list-blocks.ts            # Block listing example
│   ├── list-transactions.ts      # Transaction listing example
│   ├── batch-info.ts             # Batch info example
│   ├── list-events.ts            # Event listing example
│   └── search-example.ts         # Search functionality example
├── dist/                         # Compiled JavaScript output
├── package.json                  # Project configuration
└── tsconfig.json                 # TypeScript configuration

Basic Usage

import { getBlockByNumber, getTransaction, search } from 'blockchain-api';

// Get block information
const block = await getBlockByNumber(12345);

// Get transaction details
const tx = await getTransaction('0x123...');

// Search for a block, transaction, address, or token
const searchResult = await search('0xabc...');
if (searchResult) {
  console.log(`Found ${searchResult.type}: ${searchResult.id}`);
}

Search Functionality

The library includes a simple but powerful search feature:

import { search } from 'blockchain-api';

// Search can find blocks, transactions, addresses, or tokens
const result = await search('0x123abc...');

// Result format: { type: 'block'|'transaction'|'address'|'token', id: string }
if (result) {
  switch(result.type) {
    case 'block':
      console.log(`Found block: ${result.id}`);
      break;
    case 'transaction':
      console.log(`Found transaction: ${result.id}`);
      break;
    case 'address':
      console.log(`Found address: ${result.id}`);
      break;
    case 'token':
      console.log(`Found token: ${result.id}`);
      break;
  }
} else {
  console.log('No results found');
}

The search function returns a simple object with type and id properties, making it easy to navigate to the appropriate detail page in your application.

Package Sidebar

Install

npm i blockchain-api

Weekly Downloads

20

Version

1.1.0

License

MIT

Unpacked Size

330 kB

Total Files

127

Last publish

Collaborators

  • exatech