@jadepool/lib-bitcoin
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-alpha.1 • Public • Published

Bitcoin Transaction Builder for NodeJS

License

One of Jadepool support library - Bitcoin transaction builder.

How to install

npm install @jadepool/lib-bitcoin

How to use

  const lib = require('@jadepool/lib-bitcoin')
  const pubKey = 'ECDSA PUBLIC KEY'
  // genAddressByPubKey
  const address = lib.genAddressByPubKey(pubKey, true) // true for testnet
  // validateAddress
  const isValid = lib.validateAddress(address, true)
  // composeUnsignedTransferTx
  const transferInfo = {
    inputs: [
      { // utxo info
        address: 'fromAddress',
        scriptPubKey: 'from utxo info.',
        txid: 'from utxo info.',
        vout: 0 // from utxo info
      }
    ],
    outputs: [
      {
        address: 'toAddress',
        satoshi: 'shatoshi no decimal'
      }
    ],
    // optional for Omni(like USDT)
    omni: {
      from: 'fromAddress',
      to: 'toAddress',
      value: 'amount no decimal',
      // optional
      contract: 'omni contract', // optional, default is 6f6d6e69
      propertyId: 31, // optional, default is 31(USDT in mainnet)
    }
  }
  // return unsignedInputs
  const { inputs/* [{ vin, address, unsignedHash }] */, rawtx } = lib.composeUnsignedTransferTx(transferInfo, true)
  // buildTransferTx
  const sigs = [
    {
      vin: 0,
      signature: 'sig hex',
      pubKey: 'public key'
    }
  ]
  const { txid, rawtx } = lib.buildTransferTx(transferInfo, sigs, true)

Readme

Keywords

Package Sidebar

Install

npm i @jadepool/lib-bitcoin

Weekly Downloads

2

Version

0.1.0-alpha.1

License

MIT

Unpacked Size

11.6 kB

Total Files

7

Last publish

Collaborators

  • btspoony
  • kristieguo
  • cisaman
  • woyoutlz