JSPM

gradium-js

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 1
    • Score
      100M100P100Q17200F
    • License MIT

    A JavaScript library for fetching detailed block information from Polkadot-based blockchains

    Package Exports

    • gradium-js

    Readme

    Gradium.js

    A JavaScript library for fetching detailed block information from Polkadot-based blockchains.

    Installation

    npm install gradium-js

    Usage

    import { Gradium } from 'gradium-js';
    
    async function main() {
        // Initialize the Gradium client
        const gradium = new Gradium('wss://rpc.polkadot.io');
        await gradium.init();
    
        try {
            // Fetch block information using a block hash
            const blockInfo = await gradium.fetchBlockInfo('0x123...'); // Replace with actual block hash
            
            console.log('Block Number:', blockInfo.number);
            console.log('Block Hash:', blockInfo.hash);
            console.log('Timestamp:', blockInfo.timestamp);
            
            // Access extrinsics
            blockInfo.extrinsics.forEach(ext => {
                console.log(`Extrinsic: ${ext.section}.${ext.method}`);
            });
            
            // Access events
            blockInfo.events.forEach(event => {
                console.log(`Event: ${event.section}.${event.method}`);
            });
        } catch (error) {
            console.error('Error:', error);
        }
    }

    API Reference

    Gradium Class

    Constructor

    constructor(wsUrl: string)

    Creates a new Gradium instance with the specified WebSocket URL.

    Methods

    • init(): Promise<void> - Initializes the connection to the blockchain
    • fetchBlockInfo(hash: string): Promise<BlockInfo> - Fetches detailed block information
    • fetchFinalizedHead(): Promise<Hash> - Gets the latest finalized block hash
    • fetchHeader(hash: string): Promise<Header> - Fetches block header
    • fetchBlockHash(number: number): Promise<Hash> - Gets block hash by number
    • fetchBlock(hash: string): Promise<Block> - Fetches raw block data
    • fetchCurrentSetId(atHash: string): Promise<string> - Gets current GRANDPA set ID
    • fetchAuthorities(atHash: string): Promise<any> - Fetches GRANDPA authorities
    • hashSha3(data: string): string - Computes SHA3 hash of input data

    Block Information Structure

    {
        hash: string;          // Block hash
        number: number;        // Block number
        parentHash: string;    // Parent block hash
        stateRoot: string;     // State root hash
        extrinsicsRoot: string;// Extrinsics root hash
        timestamp: number;     // Block timestamp
        extrinsics: [         // Array of extrinsics
            {
                index: number;
                section: string;
                method: string;
                signer: string | null;
                nonce: number | null;
                isSigned: boolean;
                tip: number | null;
            }
        ];
        events: [             // Array of events
            {
                index: number;
                section: string;
                method: string;
                phase: string;
                data: any;
            }
        ];
    }

    Development

    1. Clone the repository
    2. Install dependencies: npm install
    3. Build the project: npm run build

    License

    MIT