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

@teleportdao/teleswap-sdk

v1.9.0

Published

The Teleswap SDK provides comprehensive tools and utilities for integrating Bitcoin and Polygon blockchains. It empowers developers to build decentralized applications that enable users to transfer Bitcoin assets to the Polygon network and take advantage

Downloads

34

Readme

How to Use TeleSwap SDK

First, create an instance of SDK and initialize it.

  • default bitcoin connection is using MempoolSpace but you can also use you custom bitcoinConnection
BitcoinConnectionInfo = {
  api: {
    token?: string
    provider: "BlockStream" | "MempoolSpace"
  }
  rpc?: {
    enabled?: boolean
    url: string
    headers?: {
      [key: string]: string
    }
    auth?: {
      username: string
      password: string
    }
  }
  utxo?: {
    token?: string
    provider: "BlockStream" | "NowNodes" | "MempoolSpace" | "Unisat"
  }
}

supported target networks

  • polygon
  • bsc
  • bsquared
  • bob
  • polygon_testnet

Create Instance Using Web3 Endpoint:

let testnet = false
let networkName: "polygon_testnet" | "polygon" = testnet ? "polygon_testnet" : "polygon"
const bitcoinConnection = undefined // use default

const defaultTargetNetwork = {
  networkName, // polygon bsc bsquared bob
  web3: {
    url: "https://polygon connection endpoint for web3 ",
  },
}

const unisatToken = "" // only for brc20

let sdk = new TeleswapSDK(testnet, bitcoinConnection, defaultTargetNetwork)

to interact with other target networks, you need to add them to sdk

sdk.addNetwork({
  networkName: "ethereum", //
  web3: {
    url: "https://ethereum",
  },
})

to use with metamask add network like this

sdk.addNetwork({
  networkName,
  provider: window.ethereum,
})

After creating the instance, you need to initialize the account using Mnemonic for both Bitcoin and target networks, otherwise, you can just create unsigned transactions.

  • If you want to sign Bitcoin transactions using other wallets, ignore initializing the Bitcoin account (just use SDK to create unsigned transactions).

Initialize Account Using Mnemonic

// Init Bitcoin account
let mnemonic = "..."
let bitcoinAddress = sdk.initBitcoinAccountUsingMnemonic(mnemonic)

// Init Polygon account
let polygonAddress = sdk.initEvmAccountUsingMnemonic(mnemonic)

using the following methods, you can get the addresses of Bitcoin and Polygon accounts

let bitcoinAddress = sdk.bitcoinAddress
let bitcoinAddressType = sdk.bitcoinAddressType
let targetNetworkAddress = sdk.evmAddress

Functions

Wrap

This function facilitates transferring BTC from Bitcoin to Polygon and receiving TELEBTC in return.

// If the Bitcoin account is initialized, use this function to create, sign and send wrap requests.
let amountInBTC = 0.001
let polygonRecipientAddress = "0x..."

  let bitcoinTxId = await sdk.wrap(polygonRecipientAddress, amountInBTC)


// create unsigned transaction

// You need to provide Bitcoin account details to create an unsigned transaction

const signerInfo: {
  addressType: "p2wpkh" | "p2pkh" | "p2sh-p2wpkh"
  publicKey: string
  address: string
}

const bitcoinChangeAddress = "" // Bitcoin change address

let unsignedTxResponse = await sdk.wrapUnsigned(
  polygonRecipientAddress,
  amountInBTC,
  signerInfo,
  networkName, // optional -> if not set use default target network
)

const unsignedPSBT = unsignedTxResponse.unsignedTransaction

// Sign unsignedTx
let signedTx = ...

// Send signed Tx
let bitcoinTxId = await sdk.sendSignedTransaction(signedTx)

Exchange (Bitcoin -> Polygon)

This function facilitates exchanging BTC on Bitcoin for other tokens on Polygon.

// You need to provide the relevant exchange information


let amountInBTC = 0.001
let polygonRecipientAddress = "0x..."

let {
  txId: bitcoinTxId,
  percentageFee,
  lockerAddress,
} = await sdk.wrapAndSwap(polygonRecipientAddress,amountInBTC, , exchangeTokenAddress )

Unwrap

This function facilitates burning TELEBTC on Polygon and receiving BTC in return.

let amountInBTC = 0.001
let recipientBitcoinAddress = "..."
let {
  burnTxId, // polygonTxId
  approvedTxId, // null if teleBTC approved before (polygonTxId)
  lockerAddress,
} = await sdk.unwrap(amountInBTC, recipientBitcoinAddress)

Swap And Unwrap

This function facilitates burning WMatic or other Tokens like USDC on Polygon and receiving BTC in return.

let amountInBTC = 0.001 // Expected received amount
let recipientBitcoinAddress = "..."

let exchangeInfo = {
  inputToken: "Token Contract Address",
  inputAmount: 50, // for example (50 WMatic)
  isFixedToken: true, // True if the input token amount is fixed
}

let response = await sdk.swapAndUnwrap(exchangeInfo, recipientBitcoinAddress)