Package Exports
- js-gradium
- js-gradium/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js-gradium) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Gradium.js
A backend JavaScript project for interacting with Polkadot-based blockchains, providing functionality for fetching blockchain data and handling GRANDPA consensus operations.
Overview
This project provides a set of utilities for:
- Connecting to Polkadot-based blockchains
- Fetching blocks, headers, and finalized heads
- Working with GRANDPA consensus
- Transaction handling
Setup
- Clone the repository:
git clone https://github.com/zerox-toml/gradium-js.git
cd gradium-js
- Install dependencies:
npm install
Usage
import { Gradium } from './gradium.js';
// Initialize connection
const gradium = new Gradium('wss://your-node-url');
await gradium.init();
// Fetch latest finalized block
const finalizedHead = await gradium.fetchFinalizedHead();
const block = await gradium.fetchBlock(finalizedHead);
Available Methods
Constructor
const gradium = new Gradium(wsUrl: string)
Methods
init()
Initializes the connection to the blockchain node.
fetchFinalizedHead()
Returns the hash of the latest finalized block.
fetchHeader(hash: string)
Fetches the header for a specific block hash.
fetchBlockHash(number: number)
Retrieves the block hash for a given block number.
fetchBlock(hash: string)
Fetches the complete block data for a given hash.
fetchCurrentSetId(atHash: string)
Retrieves the current GRANDPA set ID at a specific block.
fetchAuthorities(atHash: string)
Fetches the current GRANDPA authorities at a specific block.
hashSha3(data: string)
Computes SHA3-256 hash of the provided data.
sendTestTransaction(seedPhrase: string)
Sends a test transaction using the provided seed phrase.
Example Usage
Fetching Block Information
const gradium = new Gradium('wss://your-node-url');
await gradium.init();
// Get latest block
const finalizedHead = await gradium.fetchFinalizedHead();
const header = await gradium.fetchHeader(finalizedHead);
console.log('Latest block number:', header.number.toNumber());
Working with GRANDPA Consensus
const gradium = new Gradium('wss://your-node-url');
await gradium.init();
// Get current set ID
const setId = await gradium.fetchCurrentSetId(finalizedHead);
console.log('Current set ID:', setId);
// Get authorities
const authorities = await gradium.fetchAuthorities(finalizedHead);
console.log('Current authorities:', authorities);
Development
To run the project locally:
- Make sure you have Node.js installed
- Install dependencies with
npm install
- Configure your blockchain node URL in the configuration
- Run the project using
node index.js
License
MIT License - see the LICENSE file for details.