@rsksmart/btc-transaction-solidity-helper

0.0.3 • Public • Published

Bitcoin Transaction Solidity Helper

The intention of this library is to make easier to work with Bitcoin transactions in Solidity smart contracts. Since Rootstock extends Bitcoin's capabilities by enabling smart contracts it is important to be able to work with Bitcoin transactions in them.

Features

The features of this library include:

  • Bitcoin transaction output parsing: is able to receive a raw tx and return an array of structs with the tx outputs
  • Bitcoin transaction hashing: is able to receive a raw tx and return its hash
  • Bitcoin transaction output script validation: is able to receive a raw output script, validate that is from a specific type and return a result. E.g. receive a raw null-data script and return the embeded data in it
  • Bitcoin address generation: is able to generate Bitcoin the address from a specific script and also to validate if a given address was generated from a script or not.

Future features

These are some features that can increase the library capabilities in the future:

  • Bitcoin transaction input parsing: should be able to receive a raw tx and return an array of structs with the tx inputs
  • Bitcoin transaction creation: utilities for building a raw transaction inside a contract

Usage

  1. Run this command to install the contracts
   npm install @rsksmart/btc-transaction-solidity-helper
  1. Import the library in your contract
   import "@rsksmart/btc-transaction-solidity-helper/contracts/BtcUtils.sol";
  1. Use the library. E.g.:
   BtcUtils.TxRawOutput[] memory outputs = BtcUtils.getOutputs(btcTx);
   bytes memory btcTxDestination = BtcUtils.parseNullDataScript(outputs[0].pkScript, false);

Package Sidebar

Install

npm i @rsksmart/btc-transaction-solidity-helper

Weekly Downloads

5

Version

0.0.3

License

ISC

Unpacked Size

13.6 kB

Total Files

4

Last publish

Collaborators

  • luis.chavez.iov
  • maximst