
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@ctrl-tech/chains
Advanced tools
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
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.
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.
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 |
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
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 userdescription
: 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.Here's a basic example of how to use this library in your TypeScript application:
import { BitcoinProvider } from './chain.provider';
import LedgerSigner from './ledger.signer';
import { MsgBody, Msg } from '../msg';
Initialize the Bitcoin provider with the necessary configurations:
const provider = new BitcoinProvider(new IndexerDataSource(BITCOIN_MANIFEST));
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,
};
Create a transaction message using the provider:
const message: Msg = provider.createMsg(txInput);
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();
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]);
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();
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.
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!
This project is licensed under the Apache-2.0 License.
Copyright © 2024 XDEFI
FAQs
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
We found that @ctrl-tech/chains demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.