@validators-dao/solana-entry-decoder
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

SolanaStreamSDK Follow @ValidatorsDAO NPM Version NPM Downloads

@validators-dao/solana-entry-decoder

A TypeScript utility provided by Validators DAO for decoding Solana shred entry data.

Powered By Solana

This package is designed to decode Solana entries from shreds, making it easier to work with real-time data streams from the Solana blockchain.

Why Rust?

TypeScript alone cannot decode Solana shreds effectively. Therefore, Rust is utilized for efficient decoding, converting the data into JSON format suitable for handling in TypeScript environments.

Leveraging NAPI instead of WASM

This utility leverages NAPI (Node-API) instead of WebAssembly (WASM) to decode Solana shred entry data, providing significant practical advantages.

Node-API - Node.js: https://nodejs.org/api/n-api.html#node-api

Benefits of Using NAPI:

  • Performance: NAPI delivers near-native performance by directly interfacing with Rust code through bindings, minimizing overhead compared to WebAssembly.

  • Seamless Integration: NAPI simplifies the interoperation between Node.js and Rust, enabling straightforward calls and efficient memory management without extensive tooling or additional complexity.

  • Memory Efficiency: Efficient memory handling with NAPI significantly reduces risks associated with memory leaks or unnecessary garbage collection, common pitfalls when using WASM.

  • Enhanced Debugging and Maintainability: Debugging native modules built with NAPI offers clearer stack traces and robust debugging capabilities, overcoming the opaque debugging difficulties often encountered with WASM.

  • Wide Compatibility: Modules built with NAPI are natively compatible across various Node.js versions without requiring extra compilation steps or environment-specific adjustments.

Installation

npm install @validators-dao/solana-entry-decoder

Or using pnpm:

pnpm add @validators-dao/solana-entry-decoder

Usage

Direct Usage (Node.js ES Modules)

To directly import this package, you'll need to use the Node.js require function:

import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const { decodeSolanaEntries } = require('@validators-dao/solana-entry-decoder')

Recommended Usage

For TypeScript projects, it's recommended to import directly from Solana Stream SDK, which exports the decoder in a more convenient way:

pnpm add @validators-dao/solana-stream-sdk
import { decodeSolanaEntries } from '@validators-dao/solana-stream-sdk'

You can find comprehensive usage examples here.

Multi-Platform Build

To build binaries for multiple platforms (cross-compilation), you must first install Rust targets for each desired OS and architecture. Execute the following commands once on your machine to enable cross-platform builds:

rustup target add x86_64-unknown-linux-gnu      # Linux x64
rustup target add aarch64-unknown-linux-gnu     # Linux ARM64
rustup target add aarch64-apple-darwin          # macOS ARM64 (Apple Silicon)
rustup target add x86_64-apple-darwin           # macOS x64 (Intel)

Here's a concise README section in English that clearly states this is for macOS specifically:

Cross-compilation for Linux (macOS)

On macOS, to cross-compile for Linux targets (x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu), you must install the following toolchains:

brew tap messense/macos-cross-toolchains
brew install x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu zig

For Windows Users

For now please use WSL2 and follow the Linux instructions.

Build packages

pnpm i
pnpm build

// or from the root of the monorepo
pnpm -F @validators-dao/solana-entry-decoder build

Repository

This utility is part of the Solana Stream Monorepo.

Support

For support and further questions, please join our Discord server.

License

Apache-2.0 License. Refer to the license document.

Code of Conduct

All contributors must adhere to our Contributor Covenant.

Readme

Keywords

none

Package Sidebar

Install

npm i @validators-dao/solana-entry-decoder

Weekly Downloads

88

Version

2.2.0

License

Apache-2.0

Unpacked Size

2.35 MB

Total Files

9

Last publish

Collaborators

  • kishithemechanic
  • fumi