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

@xlink-network/xlink-sdk

v0.2.4

Published

XLINK js SDK

Downloads

453

Readme

XLinkSDK

XLink is designed to facilitate the transfer of digital tokens between different blockchains. Its primary purpose is to act as a bridge, enabling users to move and swap their tokens seamlessly across various blockchain ecosystems.

System Type and Purpose

XLinkSDK allows users to interact with XLink. It can be used in backend environments as well as in browsers and mobile applications. The SDK enables bidirectional transfer of coins/tokens between Bitcoin, Stacks, and various EVM including Bitcoin Layer 2s networks. Also, provides information on transfer fees, route planning, transaction size calculations and implements security features for safe transfers.

Roadmap

  • [x] Bitcoin <> EVM
  • [x] Bitcoin <> Stacks
  • [ ] Runes <> Stacks
  • [ ] BRC-20 <> Stacks
  • [x] EVM <> EVM
  • [x] EVM <> Bitcoin
  • [x] EVM <> Stacks

Installation

Prerequisites

Ensure you have the following installed:

Installation

To install the XLink SDK, use the following command:

pnpm install @xlink-network/xlink-sdk

XLink SDK API

Supported Blockchains and Tokens

KnownChainId

The KnownChainId namespace encapsulates types and utility functions to validate blockchain networks supported by the SDK. It ensures that only recognized chain IDs across Bitcoin, EVM-compatible chains, and Stacks are used.

| Namespace | mainnet | testnet | |-----------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Bitcoin | Mainnet | Testnet | | Stacks | Mainnet | Testnet | | EVM | Ethereum, BSC, CoreDAO, Bsquared, BOB, Bitlayer, Lorenzo, Merlin, AILayer, Mode | Sepolia, BSCTestnet, CoreDAOTestnet, BsquaredTestnet, BOBTestnet, BitlayerTestnet, LorenzoTestnet, MerlinTestnet, AILayerTestnet, ModeTestnet |

KnownTokenId

The KnownTokenId namespace manages the token IDs of supported cryptocurrencies across different blockchain networks within the SDK. It ensures that only recognized tokens specific to Bitcoin, EVM-compatible chains, and Stacks are used.

Namespaces

| Namespace | Token | |------------|------------------------------------------------------------------------------------------------------| | Bitcoin | BTC | | Stacks | ALEX, aBTC, sLUNR, sSKO, sUSDT, uBTC, vLiALEX, vLiSTX |
| EVM | ALEX, aBTC, BTCB, LUNR, SKO, sUSDT, uBTC, USDT, vLiALEX, vLiSTX, WBTC, wuBTC |

Future Support: Support for Runes and BR20 tokens on the Bitcoin network is planned for a future update.

XLink SDK

The XLinkSDK object contains the most important functions of this library, all grouped together. To create it:

const theSdk = new XLinkSDK();

For detailed API documentation, including a full list of available methods and their usage, please refer to:

SDK API Documentation

Use Cases

Create an instance of the SDK with default options

import{ XLinkSDK } from '@xlink-network/xlink-sdk';
const xlinkSdk = new XLinkSDK();
  1. Bridge from Stacks
import{ 
    BridgeInfoFromStacksInput, 
    BridgeFromStacksInput,
    KnownChainId,
    KnownTokenId, 
} from '@xlink-network/xlink-sdk';

// Get bridge info
const bridgeInfo = await xlinkSdk.bridgeInfoFromStacks({    
    fromChain: KnownChainId.Stacks.Mainnet,
    toChain: KnownChainId.EVM.Ethereum,
    fromToken: KnownTokenId.Stacks.sUSDT,
    toToken: KnownTokenId.EVM.USDT,
    amount: 100,
} as BridgeInfoFromStacksInput);
console.log("Bridge Info:", bridgeInfo);

// Perform the bridge operation
const result = await xlinkSdk.bridgeFromStacks({ 
    fromChain: KnownChainId.Stacks.Mainnet,
    toChain: KnownChainId.EVM.Ethereum,
    fromToken: KnownTokenId.Stacks.sUSDT,
    toToken: KnownTokenId.EVM.USDT,
    toAddress: "0x...",
    amount: 10,
    sendTransaction: async (tx: ContractCallOptions) => {
        // Implementation for sending transaction from Stacks mainnet
        const network = new StacksMainnet();
        const transaction = await makeContractCall({
            contractAddress: tx.contractAddress,
            contractName: tx.contractName,
            functionName: tx.functionName,
            functionArgs: tx.functionArgs,
            senderKey: /* sender address private key */,
            network,
            postConditions: tx.postConditions,
            anchorMode: tx.anchorMode,
        });
        const broadcastResponse = await broadcastTransaction(transaction, network);
        return broadcastResponse.txid;
    } 
} as BridgeFromStacksInput);
console.log("Transaction ID:", result.txid);
  1. Bridge from EVM
import { 
    BridgeInfoFromEVMInput,
    BridgeFromEVMInput,
    KnownChainId,
    KnownTokenId,
} from '@xlink-network/xlink-sdk';

// Get bridge info
const bridgeInfo = await xlinkSdk.bridgeInfoFromEVM({
    fromChain: KnownChainId.EVM.Ethereum,
    toChain: KnownChainId.Stacks.Mainnet,
    fromToken: KnownTokenId.EVM.USDT,
    toToken: KnownTokenId.Stacks.sUSDT,
    amount: 100,
} as BridgeInfoFromEVMInput);
console.log("Bridge Info:", bridgeInfo);

// Perform the bridge operation
const result = await xlinkSdk.bridgeFromEVM({
    fromChain: KnownChainId.EVM.Ethereum,
    toChain: KnownChainId.Stacks.Mainnet,
    fromToken: KnownTokenId.EVM.USDT,
    toToken: KnownTokenId.Stacks.sUSDT,
    toAddress: "0x...",
    amount: 10,
    sendTransaction: // Implementation for sending transaction from EVM chain
} as BridgeFromEVMInput);
console.log("Transaction ID:", result.txHash);
  1. Bridge from Bitcoin
import { 
    BridgeInfoFromBitcoinInput,
    BridgeFromBitcoinInput,
    KnownChainId,
    KnownTokenId,
} from '@xlink-network/xlink-sdk';

// Get bridge info
const bridgeInfo = await xlinkSdk.bridgeInfoFromBitcoin({
    fromChain: KnownChainId.Bitcoin.Mainnet,
    toChain: KnownChainId.EVM.Ethereum,
    amount: 1,
} as BridgeInfoFromBitcoinInput);
console.log("Bridge Info:", bridgeInfo);

// Perform the bridge operation
const result = await xlinkSdk.bridgeFromBitcoin({
    fromChain: KnownChainId.Bitcoin.Mainnet,
    toChain: KnownChainId.EVM.Ethereum,
    fromToken: KnownTokenId.Bitcoin.BTC,
    toToken: KnownTokenId.EVM.WBTC,
    fromAddress: "bitcoin address",
    fromAddressScriptPubKey: scriptPubKey,
    toAddress: "0x...",
    amount: 1,
    networkFeeRate: 10n,
    reselectSpendableUTXOs: // Implementation for reselect UTXOs
    signPsbt: // Implementation for signing PSBT
} as BridgeFromBitcoinInput);
console.log("Transaction ID:", result.tx);