Bitcoin: Bitcoin API for getting an input script?

We start with the interactions of bitcoin nodes: a guide to the bitcoin API

Bitcoin is a decentralized digital currency that relies on complex cryptographic techniques, including the Blockchain basic protocol. In order to get an overview of network behavior and improving our understanding, how it works, it is an excellent approach to the interaction with the node helf through the API interface (application programming). However, access to certain nodes or data may be limited as a result of safety measures. Fortunately, we will provide you with a detailed guide to access the entry of bitcoin nodes through Varous Languages.

Calling the right API interface

To get started, select the API that provides access to the status and transaction of the Bitcoin network. The most commonly used API interfaces are:

* API Bitcoin-Uzlov : This is an official API for access to the bitcoin nodes. It allows you to get information about the heads of the blocks, the outputs of the transactions and others.

Open Bitcoin networks

: Open BNB Network (OBN) is a bitcoin network fork that provides alternative API for interaction with nodes.

In this article, we will focus on using the Bitcoin Nodes API interface.

Setting up your environment

Before you start code, make sure you have:

  • Attached cryptocurrency wallet and node.

  • Installed library Curl or Python of your choice (we recommend using ‘Requestfor Python).

  • The basic knowledge of programming in C

    or Python.

Entering the Loading Blocks and outputs of transaction

Here is an example of how you can use API Bitcoin-Node in Python:

Python

Import requirements

From Cryptograph.Hazmat.Primitines to import serialization, hash

From Cryptograph.hazmat.Backends import default_backend

From bitcoinlib.crypto import prizes_to_p2sh_script, pubkey_to_bytes

Set the URL of the node and credentials

node_url = "http: // localhost: 8333"

Username = "Your-USERNAME"

Password = "Your-Password"

Create a pair of PGP keys to sign script signature

pgp_key = serialization.load_der_x509_certificate (

FileName = "Path/To/Your-Private-Key.PEM", Backen = default_backnd ()

)

Def Get_block_Head (Node_url, Username, Password):

Headers = {"Authorization": F "Basic {Username}: {Password}"}

Response = Requests.get (F "{node_url} /block.Hlock", headers = heads)

Return Response.Json ()

Def Get_transaction_output (Node_url, block_theader_json, transaction_id):

Headers = {"Authorization": F "Basic {Username}: {Password}"}

Response = Requests.get (F "{node_url}/Txout/{transaction_id}", headers = headers)

Return Response.Json ()

Example of use:

Block_Head = Get_block_head (Node_url, Username, Password)

Print (Block_Head)

Transaction_output = Get_transaction_output (Node_url, Block_Head ['Header'], "Your-Transaction-ID")

Print (Transaction_output)

put it all together

If you want to put everything in one feature, you can create a class that processes the interaction of the knots. Be sure to replace the values ​​of the surrender symbols (eg “Node_url," Username "and" password ") with your real credentials.

` Python

Import requirements

From Cryptograph.hazmat.Primitive Import Serialization, Hash

From Cryptograph.hazmat.Backends import default_backend

Class Bitcoinnodeappi:

Def __init __ (self):

self.node_url = “http: // localhost: 8333”

self.username = “Your-USERNAME”

self.password = “Your-Password”

Def Get_block_Head (self):

Headers = {“Authorization”: F “Basic {self.username}: {self.password}”}

Response = Requests.get (F “{self.node_url} /block.Hlock”, headers = heads)

Return Response.Json ()

Def Get_transaction_output (self, block_theader_json):

Headers = {“Authorization”: F “Basic {self.username}: {self.password}”}

Response = Requests.get (F “{self.

BITCOIN CASH