Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ctrl-tech/chains

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctrl-tech/chains

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

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

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

ChainProviderDatasourcesSignersCustom chain
BitcoinBitcoinIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorNo
EthereumEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
BNB Smart ChainEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
PolygonEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
AvalancheEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
FantomEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
ArbitrumEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
AuroraEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
Canto EVMEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
OptimismEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
KlaytnEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
CronosEVMIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
BinanceBinanceIndexerSeedPhrase, PrivateKey, Ledger, TrezorNo
BitcoinCashBitcoinCashIndexerSeedPhrase, PrivateKey, Ledger, TrezorNo
Cosmos HubCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
OsmosisCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
AxelarCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
JunoCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
CrescentCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
KavaCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
StargazeCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
AkashCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
CronosCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
KujiraCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
StrideCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
MarsCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
TerraCosmosIndexer, ChainSeedPhrase, PrivateKey, Ledger, TrezorYes
DogecoinDogecoinIndexerSeedPhrase, PrivateKey, Ledger, TrezorNo
LitecoinLitecoinIndexerSeedPhrase, PrivateKey, Ledger, TrezorNo
SolanaSolanaIndexer, ChainSeedPhrase, PrivateKey, LedgerNo
ThorChainThorChainIndexer, ChainSeedPhrase, LedgerNo
MayaChainThorChainIndexer, ChainSeedPhrase, LedgerNo
TronTronIndexer, ChainSeedPhrase, PrivateKey, LedgerNo

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

FAQs

Package last updated on 27 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc