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

@oraichain/orai-bitcoin

v2.0.0

Published

A JavaScript library for accepting Bitcoin deposits with Interchain Deposits to any IBC-enabled blockchain, powered by Nomic.

Downloads

137

Readme

A JavaScript library for accepting Bitcoin deposits with Interchain Deposits to any IBC-enabled blockchain, powered by Nomic.

Installation

npm install nomic-bitcoin

Interchain Deposits

import { generateDepositAddress } from 'nomic-bitcoin'

let depositInfo = await generateDepositAddress({
  relayers: ['https://relayer.nomic-testnet.mappum.io:8443'],
  channel: 'channel-0', // IBC channel ID on Nomic
  network: 'testnet',
  receiver: 'cosmos1...', // bech32 address of the depositing user
})

console.log(depositInfo)
/*
{
  code: 0,
  bitcoinAddress: "tb1q73yhgsjedp2uuwjew6zcj0kurryyue2zqjdgn5g5cf7w4krwgtusgsmpku",
  expirationTimeMs: 1624296000000,
  bridgeFeeRate: 0.015,
  minerFeeRate: 0.0001,
  qrCodeData: "data:image/svg+xml;base64,...",
}
*/

Bitcoin sent to bitcoinAddress before the expiration date will be automatically IBC-transferred over the specified channel and should appear in the user's account with no further interaction required.

QR code

A QR code similar to the below will be returned as a base64 data URL string and should be shown to users on desktop devices for ease of use with mobile wallets.

QR code example

The returned data URL can be used as the src attribute on img elements:

<img src={qrCodeData} />

Capacity limit

The bridge currently has a capacity limit, which is the maximum amount of BTC that can be held in the bridge at any given time. When the capacity limit is reached, relayers will reject newly-broadcasted deposit addresses.

If the bridge is over capacity, the response code in depositInfo will be 2.

let depositInfo = await generateDepositAddress(opts)
if (depositInfo.code === 2) {
  console.error(`Capacity limit reached`)
}

Partner chains should communicate clearly to the user that a deposit address could not be safely generated because the bridge is currently over capacity.

Deposit address expiration

When a deposit address is successfully generated, an expiration time in milliseconds is returned in depositInfo.

let depositInfo = await generateDepositAddress(opts)
if (depositInfo.code === 0) {
  let { expirationTimeMs, bitcoinAddress } = depositInfo
  console.log(
    `Deposit address ${bitcoinAddress} expires at ${expirationTimeMs}`
  )
}

It is critical that the user understands that deposits to this Bitcoin address will be lost if they are sent after the expiration time. Addresses typically expire 4-5 days after creation. Do not save the address for later use, and warn the user not to reuse the address, even though multiple deposits to the same address will work as expected before the address expires.

Fee rates

The Nomic bridge will deduct a fee from incoming deposits. The fee rate is currently a percentage of the deposit amount, and is returned in depositInfo.

let depositInfo = await generateDepositAddress(opts)
if (depositInfo.code === 0) {
  let { bridgeFeeRate, minerFeeRate, bitcoinAddress } = depositInfo
  console.log(
    `The fee rate for deposits to ${bitcoinAddress} is ${
      bridgeFeeRate * 100
    }% and ${minerFeeRate} sats per byte`
  )
}

Additionally, a small fixed fee will deducted by Bitcoin miners before the deposit is processed.

These fees should be communicated clearly to the user as "Bridge fee" (a percentage) and "Bitcoin miner fee" respectively.

Pending deposits

You can query all pending deposits by receiver address with getPendingDeposits:

import { getPendingDeposits } from 'nomic-bitcoin'

let pendingDeposits = await getPendingDeposits(relayers, address)
console.log(pendingDeposits) // [{ confirmations: 2, txid: '...', vout: 1, amount: 100000, height: 812000 }]

Usage guidelines

  • Include multiple relayers. See the Nomic docs for information about running a relayer.
  • Display a deposit address QR code on desktop for mobile Bitcoin wallets.
  • Communicate bridge and miner fees.
  • Display the deposit address expiration time.

Status

Interchain Deposits and Withdrawls will be enabled in a release pushing October 27, 2023 with an estimated activation on October 30, 2023.