2.0.0 • Published 7 months ago

nomic-bitcoin v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

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.

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.

1.0.2

7 months ago

1.1.0

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago

1.0.4

7 months ago

2.0.0

7 months ago

1.0.3

7 months ago

0.1.0

2 years ago