Skip to content

Commit

Permalink
Merge pull request #8 from tatumio/btc-getrawtransaction
Browse files Browse the repository at this point in the history
BTC RPC docs update
  • Loading branch information
c00p3erCZ authored May 21, 2024
2 parents c025a92 + b9af930 commit 20f9f51
Show file tree
Hide file tree
Showing 2 changed files with 273 additions and 0 deletions.
121 changes: 121 additions & 0 deletions v1.0/RPC Nodes/rpc-utxo/rpc-btc/rpc-btc-createrawtransaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: "createrawtransaction"
slug: "rpc-btc-createrawtransaction"
excerpt: "Bitcoin RPC"
category: "6620f7e31ea673003624a8ce"
hidden: false
metadata:
description: "Bitcoin RPC"
image: []
keywords: "btc, rpc"
robots: "index"
createdAt: "Wed Mar 06 2024 10:35:44 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 14:43:58 GMT+0000 (Coordinated Universal Time)"
---
[block:html]
{
"html": "<div style=\"padding: 10px 20px; border-radius: 5px; background-color: #e6e2ff; margin: 0 0 30px 0;\">\n <h5>Archive Method</h5>\n <p>Only on the full archive nodes. Complex queries might take longer and incur additional cost</p>\n</div>"
}
[/block]


### How to use it



```typescript
// yarn add @tatumio/tatum

import { TatumSDK, Bitcoin, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Bitcoin>({network: Network.BITCOIN})

const result = await tatum.rpc.createRawTransaction([
{
"txid": "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234",
"vout": 0
}
],
{
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa": 0.01
})

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
```



### Overview

The `createrawtransaction` RPC method creates an unsigned raw transaction that spends a set of previous transaction outputs to a set of new addresses with specific amounts. The method can be used to create custom transactions, which can then be signed and broadcast to the Bitcoin network.

[block:embed]
{
"html": false,
"url": "https://codepen.io/tatum-devrel/pen/oNQarzo",
"href": "https://codepen.io/tatum-devrel/pen/oNQarzo",
"typeOfEmbed": "iframe",
"height": "300px",
"width": "100%",
"iframe": true,
"provider": "codepen.io"
}
[/block]

### Parameters

- `inputs`: (array, required) An array of objects, each specifying a previous transaction output to spend.
- `txid`: (string, required) The transaction ID of the previous transaction output to spend.
- `vout`: (numeric, required) The index of the output to spend from the previous transaction.
- `sequence`: (numeric, optional) default=depends on the value of the 'replaceable' and 'locktime' arguments) The sequence number
- `outputs`: (object, required) An object with the key-value pairs representing the receiving address and the amount to be sent (in BTC).
- `locktime`: (numeric, optional, default=0) The lock time for the transaction. It can be used to specify the earliest time or block height at which the transaction can be included in a block.
- `replaceable`: (boolean, optional, default=false) **Marks this transaction as BIP125-replaceable.** Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible.

### Return Object

- (string) A hex-encoded raw transaction.

### JSON Examples

Request example:

{% code overflow="wrap" lineNumbers="true" %}

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "createrawtransaction",
"params": [
[
{
"txid": "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234",
"vout": 0
}
],
{
"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa": 0.01
}
]
}
```

{% endcode %}

Response example:

{% code overflow="wrap" lineNumbers="true" %}

```json
{
"result": "02000000013412cdab3412cdab3412cdab3412cdab3412cdab3412cdab3412cdab3412cdab0000000000fdffffff0140420f00000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000",
"error": null,
"id": 1
}

```

{% endcode %}

\\
152 changes: 152 additions & 0 deletions v1.0/RPC Nodes/rpc-utxo/rpc-btc/rpc-btc-decoderawtransaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
title: "decoderawtransaction"
slug: "rpc-btc-decoderawtransaction"
excerpt: "Bitcoin RPC"
category: "6620f7e31ea673003624a8ce"
hidden: false
metadata:
description: "Bitcoin RPC"
image: []
keywords: "btc, rpc"
robots: "index"
createdAt: "Wed Mar 06 2024 10:35:44 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Sat Apr 06 2024 14:43:58 GMT+0000 (Coordinated Universal Time)"
---
[block:html]
{
"html": "<div style=\"padding: 10px 20px; border-radius: 5px; background-color: #e6e2ff; margin: 0 0 30px 0;\">\n <h5>Archive Method</h5>\n <p>Only on the full archive nodes. Complex queries might take longer and incur additional cost</p>\n</div>"
}
[/block]


### How to use it



```typescript
// yarn add @tatumio/tatum

import { TatumSDK, Bitcoin, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Bitcoin>({network: Network.BITCOIN})

const result = await tatum.rpc.decodeRawTransaction("02000000013412cdab3412cdab3412cdab3412cdab3412cdab3412cdab3412cdab3412cdab0000000000fdffffff0140420f00000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000")

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs
```



### Overview

The `decoderawtransaction` RPC method decodes a serialized (hex-encoded) raw transaction and displays its information in a human-readable format. This method is useful for inspecting raw transactions before broadcasting them to the Bitcoin network or for debugging purposes.

[block:embed]
{
"html": false,
"url": "https://codepen.io/tatum-devrel/pen/xxQMegr",
"href": "https://codepen.io/tatum-devrel/pen/xxQMegr",
"typeOfEmbed": "iframe",
"height": "300px",
"width": "100%",
"iframe": true,
"provider": "codepen.io"
}
[/block]

### Parameters

- `hex_string`: (string, required) The serialized raw transaction in hex format.

### Return Object

An object containing the decoded raw transaction information:

- `txid`: (string) The transaction ID.
- `hash`: (string) The transaction hash.
- `version`: (numeric) The transaction version.
- `size`: (numeric) The transaction size in bytes.
- `vsize`: (numeric) The virtual transaction size in bytes.
- `weight`: (numeric) The transaction weight.
- `locktime`: (numeric) The lock time for the transaction.
- `vin`: (array) An array of objects, each representing an input of the transaction.
- `txid`: (string) The transaction ID of the previous transaction output to spend.
- `vout`: (numeric) The index of the output to spend from the previous transaction.
- `scriptSig`: (object) The script used to redeem the previous transaction output.
- `asm`: (string) The assembly representation of the script.
- `hex`: (string) The hex-encoded script.
- `sequence`: (numeric) The sequence number.
- `vout`: (array) An array of objects, each representing an output of the transaction.
- `value`: (numeric) The amount sent to the output.
- `n`: (numeric) The index of the output.
- `scriptPubKey`: (object) The script used to lock the output.
- `asm`: (string) The assembly representation of the script.
- `hex`: (string) The hex-encoded script.
- `reqSigs`: (numeric) The required number of signatures.
- `type`: (string) The type of the script (e.g., 'pubkeyhash').
- `addresses`: (array) An array of Bitcoin addresses associated with the output.

### JSON Examples

Request example:

{% code overflow="wrap" lineNumbers="true" %}

```json
{
"jsonrpc": "2.0",
"method": "decoderawtransaction",
"params": ["02000000013412cdab3412cdab3412cdab3412cdab3412cdab3412cdab3412cdab3412cdab0000000000fdffffff0140420f00000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000"],
"id": 1
}
```

{% endcode %}

Response example:

{% code overflow="wrap" lineNumbers="true" %}

```json
{
"result": {
"txid": "9f5f5e6d36b6a284f52626be505175e43900009e7aa1b88fce74fcd30f0dc258",
"hash": "9f5f5e6d36b6a284f52626be505175e43900009e7aa1b88fce74fcd30f0dc258",
"version": 2,
"size": 85,
"vsize": 85,
"weight": 340,
"locktime": 0,
"vin": [
{
"txid": "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234",
"vout": 0,
"scriptSig": {
"asm": "",
"hex": ""
},
"sequence": 4294967293
}
],
"vout": [
{
"value": 0.01,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 OP_EQUALVERIFY OP_CHECKSIG",
"desc": "addr(1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa)#632p52jr",
"hex": "76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac",
"address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"type": "pubkeyhash"
}
}
]
},
"error": null,
"id": 1
}
```

{% endcode %}

\\

0 comments on commit 20f9f51

Please sign in to comment.