diff --git a/docs/02-developers/08-libraries/bitcoin-tx-solidity-helper.md b/docs/02-developers/08-libraries/bitcoin-tx-solidity-helper.md index 2194b073..e311123d 100644 --- a/docs/02-developers/08-libraries/bitcoin-tx-solidity-helper.md +++ b/docs/02-developers/08-libraries/bitcoin-tx-solidity-helper.md @@ -1,11 +1,18 @@ --- -title: How to Handle Bitcoin Transactions in Solidity -tags: [rif, rootstock, solidity, bitcoin, smart contracts, libraries, bitcoin transactions] sidebar_label: Bitcoin Transaction Solidity Helper Library sidebar_position: 300 -description: "This guide demonstrates to a developer how to handle Bitcoin transactions in a Solidity Smart contract, we will also learn how to parse transactions, hash transactions and validate scripts for bitcoin transactions" +title: How to Handle Bitcoin Transactions in Solidity +description: 'This guide demonstrates to a developer how to handle Bitcoin transactions in a Solidity Smart contract, we will also learn how to parse transactions, hash transactions and validate scripts for bitcoin transactions.' +tags: [rif, rootstock, solidity, bitcoin, smart contracts, libraries, bitcoin transactions] --- +:::info[Note] +If you wish to suggest changes on this document, please open a PR on the [Bitcoin Transaction Solidity Helper](https://github.com/rsksmart/btc-transaction-solidity-helper.git) +::: + + +# BTC Transaction Solidity Helper + Bitcoin, a decentralized digital currency, serves as both a store of value and a means of transferring wealth. Its security is rooted in the blockchain, a distributed ledger maintained by a network of miners. These miners expend significant computational power and energy to create new blocks, which are added to the blockchain every 10 minutes. The more hashing power contributed by miners, the more secure the network becomes. [Learn more about Bitcoin](https://developer.bitcoin.org/index.html). Rootstock, the pioneering open-source smart contract platform built on Bitcoin, aims to enhance the Bitcoin ecosystem by introducing smart contract functionality, near-instant payments, and improved scalability. Its comprehensive technology stack, encompassing Rootstock smart contracts and the Rootstock Infrastructure Framework, is designed to foster a more equitable and inclusive financial system. Read more about the [Rootstock Stack](/concepts/fundamentals/stack/). @@ -21,6 +28,11 @@ The features of the Bitcoin Solidity Helper library include: 4. 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. 5. Bitcoin address validation: This checks if a Bitcoin address conforms to a particular type or format. It validates if a Bitcoin address is of a given type or not. +## Versioning +Current version is ![npm version](https://img.shields.io/npm/v/@rsksmart/btc-transaction-solidity-helper.svg) + +To check the NPM package, please check [Bitcoin Solidity Helper NPM Package.](https://www.npmjs.com/.package/@rsksmart/btc-transaction-solidity-helper) + ## Prerequisites * Knowledge of Solidity and how to write smart contracts. * [Bitcoin Solidity Helper Package](https://github.com/rsksmart/btc-transaction-solidity-helper/pkgs/npm/btc-transaction-solidity-helper) @@ -103,6 +115,7 @@ require(expectedValue <= outputs[0].value, "incorrect amount"); The value field of the output structure is in satoshis. ::: + ## Hashing Transactions The hash algorithm used in the Bitcoin Network is just the `SHA256(SHA256())` of the serialized transaction. The library exposes one function that will apply this hash algorithm to any byte array passed to it, making it easy to calculate the transaction id of any raw transaction present in the contract. @@ -163,6 +176,13 @@ bytes memory btcTxDestination = BtcUtils.outputScriptToAddress( ## Conclusion Congratulations, we have successfully learnt how to use the Solidity Helper library to parse, hash, and validate scripts within Bitcoin transactions. By using this library, developers can gain valuable insights into Bitcoin transaction data and build more sophisticated smart contract dApps on Rootstock. +### Future features **Some future enhancements to the library includes:** * Transaction Input Parsing: The ability to extract and analyze transaction input data to receive a raw tx and return an array of structs with the tx inputs. * Transaction Creation: Utilities to facilitate the creation of raw Bitcoin transactions within smart contracts. + +## Contribution Guidelines +* Please refer to the Rootstock Contribution Guidelines for more information on how to contribute to this project. + +## License: +MIT License - Copyright (c) 2023 Rootstock.