npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ctrl-tech/chains

v1.0.0

Published

This TypeScript library is designed to provide a unified interface for working with multiple blockchain networks, allowing developers to interact with various blockchain chains seamlessly. It supports a wide range of features and blockchain networks, maki

Downloads

6

Readme

Chainslib

This TypeScript library is designed to provide a unified interface for working with multiple blockchain networks, allowing developers to interact with various blockchain chains seamlessly. It supports a wide range of features and blockchain networks, making it a versatile tool for blockchain development.

Features

This library offers the following key features:

Hardware Wallet Support: It provides integration with Ledger and Trezor hardware wallets for enhanced security in blockchain transactions.

Wallet Types: You can work with both seed phrase and private key wallets for managing your blockchain assets.

Standardized RPC Interface: The library offers a consistent RPC interface for fetching blockchain information and broadcasting transactions across different supported chains.

Supported Chains

This library currently supports the following blockchain networks: // example for fallback data source // example with custom provider

| Chain | Provider | Datasources | Signers | Custom chain | | --------------- | ------------------------------------------------------------------------------- | -------------- | -------------------------------------- | ------------ | | Bitcoin | Bitcoin | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | No | | Ethereum | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | BNB Smart Chain | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Polygon | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Avalanche | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Fantom | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Arbitrum | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Aurora | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Canto EVM | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Optimism | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Klaytn | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Cronos | EVM | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Binance | Binance | Indexer | SeedPhrase, PrivateKey, Ledger, Trezor | No | | BitcoinCash | BitcoinCash | Indexer | SeedPhrase, PrivateKey, Ledger, Trezor | No | | Cosmos Hub | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Osmosis | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Axelar | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Juno | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Crescent | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Kava | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Stargaze | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Akash | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Cronos | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Kujira | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Stride | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Mars | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Terra | Cosmos | Indexer, Chain | SeedPhrase, PrivateKey, Ledger, Trezor | Yes | | Dogecoin | Dogecoin | Indexer | SeedPhrase, PrivateKey, Ledger, Trezor | No | | Litecoin | Litecoin | Indexer | SeedPhrase, PrivateKey, Ledger, Trezor | No | | Solana | Solana | Indexer, Chain | SeedPhrase, PrivateKey, Ledger | No | | ThorChain | ThorChain | Indexer, Chain | SeedPhrase, Ledger | No | | MayaChain | ThorChain | Indexer, Chain | SeedPhrase, Ledger | No | | Tron | Tron | Indexer, Chain | SeedPhrase, PrivateKey, Ledger | No |

Installation

To use this library in your TypeScript project, you can install it via npm or yarn:

npm install @ctrl-tech/chains
# or
yarn add @ctrl-tech/chains

Manifest

Each provider may have different manifests, but they share common fields. For more details, please refer to the README of the respective provider.

  • name: The name of the blockchain network. Uses only for display name to user
  • description: A brief description or additional information about the blockchain network.
  • rpcURL: The URL endpoint for the Remote Procedure Call (RPC) interface of the blockchain network.
  • chainSymbol: The symbol representing the blockchain network.
  • blockExplorerURL: The URL of a block explorer service specific to the blockchain. Block explorers allow users to view details about blocks, transactions, addresses, and other blockchain-related data.
  • chainId: The unique identifier of the blockchain network.
  • chain: The name of the blockchain network. If you are using IndexerDataSource, it must be obtained from the registry.
  • decimals: The number of decimal places used by the native currency of the blockchain network.
  • feeGasStep: An object containing gas step values for different fee levels (high, medium, low) used in transactions.

Usage

Here's a basic example of how to use this library in your TypeScript application:

1. Import Required Modules

import { BitcoinProvider } from './chain.provider';
import LedgerSigner from './ledger.signer';
import { MsgBody, Msg } from '../msg';

2. Initialize Bitcoin Provider

Initialize the Bitcoin provider with the necessary configurations:

const provider = new BitcoinProvider(new IndexerDataSource(BITCOIN_MANIFEST));

3. Create Transaction Input

Define the transaction input data, including the sender (from), recipient (to), and the amount to send.

const txInput: MsgBody = {
  from: 'FROM ADDRESS',
  to: 'TO ADDRESS',
  amount: 0.000001,
};

4. Create a Transaction Message

Create a transaction message using the provider:

const message: Msg = provider.createMsg(txInput);

5. Sign the Transaction with Ledger

Use the LedgerSigner to sign the transaction. Provide the message and the derivation path:

const transport = await Transport.create();
const signer = new LedgerSigner(transport);
const derivationPath = "m/84'/0'/0'/0/0";

await signer.sign(message, derivationPath);
// finally close
transport.close();

6. Broadcast the Transaction

Now that the transaction is signed, you can broadcast it to the Bitcoin network using the BitcoinProvider. This step assumes that the transaction is already signed within the message.

await provider.broadcast([message]);

Fallback datasource

  • If an error occurs while fetching data from the primary data source, the FallbackDataSource will automatically switch to one of the alternative data sources configured in the constructor.
  • The number of retry attempts and the order in which the alternative data sources are used can be customized based on the requirements and preferences of the application.
import { FallbackDataSource } from '@ctrl-tech/chains-core';
import { EvmProvider, EVM_MANIFESTS } from '@ctrl-tech/chains-evm';

const provider = new EvmProvider(
  new FallbackDataSource(
    EVM_MANIFEST.ethereum,
    {
      attempts: 5,
    },
    new EvmProvider.dataSourceList.IndexerDataSource(EVM_MANIFEST.ethereum),
    new EvmProvider.dataSourceList.ChainDataSource(EVM_MANIFEST.ethereum)
  )
);

// The same as any other provider
const response = await provider.getBalance(
  '0x1234567890123456789012345678901234567890'
);
const data = await response.getData();

Retrieving a Transaction

1. Get Transaction Hash

If you have a transaction hash, you can retrieve the transaction details. Use the getTransaction method of the BitcoinProvider:

const txHash = 'TX HAS';
const txData = await provider.getTransaction(txHash);

The txData object will contain transaction details, including the transaction hash.

Contribution

Please make sure to read the Contributing Guide before making a pull request. If you have a Chainslib-related project or feature request, feel free to open an issue.

Thank you to all the people who already contributed to Chainslib!

License

This project is licensed under the Apache-2.0 License.

Copyright © 2024 XDEFI