Skip to content

Commit

Permalink
Automated update from repository
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 17, 2024
1 parent 5388708 commit 778a5e2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions docs/02-developers/08-libraries/bitcoin-tx-solidity-helper.md
Original file line number Diff line number Diff line change
@@ -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/).
Expand All @@ -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)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

0 comments on commit 778a5e2

Please sign in to comment.