BitcoinMethods

getrawtransaction

The getrawtransaction RPC method is utilized to retrieve raw transaction data from the Bitcoin blockchain.

getrawtransaction

Overview

The 'getrawtransaction' RPC method is utilized to retrieve raw transaction data from the Bitcoin blockchain.

Request

shell

wget --no-check-certificate --quiet \
  --method POST \
  --timeout=0 \
  --header 'Content-Type: application/json' \
  --header 'accept: application/json' \
  --header 'X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY' \
  --body-data '{"jsonrpc":"2.0","id":1,"method":"getrawtransaction","params": [ ]}' \
   'https://bitcoin-mainnet.node.coinapi.io'

csharp

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://bitcoin-mainnet.node.coinapi.io");
request.Headers.Add("accept", "application/json");
request.Headers.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY");
var content = new StringContent("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getrawtransaction\",\"params\": [ ]}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

php

<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json',
  'accept' => 'application/json',
  'X-CoinAPI-Key' => '73034021-THIS-IS-SAMPLE-KEY'
];
$body = '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getrawtransaction",
  "params": []
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();

?>

python

import http.client
import json

conn = http.client.HTTPSConnection("mainnet-bitcoin.node.coinapi.io")
payload = json.dumps({
"jsonrpc": "2.0",
"id": 1,
"method": "getrawtransaction",
"params": []
})
headers = {
'Content-Type': 'application/json',
'accept': 'application/json',
'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'
}
conn.request("POST", "/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

javascript

var settings = {
  "url": "https://bitcoin-mainnet.node.coinapi.io",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json",
    "accept": "application/json",
    "X-CoinAPI-Key": "73034021-THIS-IS-SAMPLE-KEY"
  },
  "data": JSON.stringify({
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getrawtransaction",
    "params": []
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});

go

package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

url := "https://bitcoin-mainnet.node.coinapi.io"
method := "POST"

payload := strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"getrawtransaction","params": [ ]}`)

client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("accept", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")

res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

ruby

require "uri"
require "json"
require "net/http"

url = URI("https://bitcoin-mainnet.node.coinapi.io")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["accept"] = "application/json"
request["X-CoinAPI-Key"] = "73034021-THIS-IS-SAMPLE-KEY"
request.body = JSON.dump({
"jsonrpc": "2.0",
"id": 1,
"method": "getrawtransaction",
"params": []
})

response = https.request(request)
puts response.read_body

java

OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getrawtransaction\",\"params\": [ ]}");
Request request = new Request.Builder()
  .url("https://bitcoin-mainnet.node.coinapi.io")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("accept", "application/json")
  .addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
  .build();
Response response = client.newCall(request).execute();

Request Parameters

  1. txid (String) (Required):
  • Description: Identifies the transaction.
  1. verbose (Integer):
  • Default: 0
  • Description: Determines the format of the response.
    • 0: Returns hex-encoded data.
    • 1: Returns a JSON object.
    • 2: Returns a JSON object inclusive of fee and prevout details.
  1. blockhash (String):
  • Description: Specifies the block to search for the transaction.

Response

Response when verbose is true:

{
  "result": {
    "in_active_chain": true,
    "hex": "01000000014fe3a69...",
    "txid": "4d3c3bf037d4a1e8598b5d...",
    "hash": "9a3bb560407fe8659c4e...",
    "size": 225,
    "vsize": 144,
    "weight": 573,
    "version": 2,
    "locktime": 0,
    "vin": [
      {
        "txid": "e29c7c3997a9f7c67c...",
        "vout": 0,
        "scriptSig": {
          "asm": "3045022100d29d8a651edf7...",
          "hex": "473044022051d81..."
        },
        "sequence": 4294967295,
        "txinwitness": [
          {
            "hex": "3045022100d29d8..."
          }
        ]
      }
    ],
    "vout": [
      {
        "value": 0.8995,
        "n": 0,
        "scriptPubKey": {
          "asm": "OP_DUP OP_HASH160 7f9b1a...",
          "hex": "76a9147f9b1a7e...",
          "desc": "pkh([dab5b6a1/44'/0'/0'/0]03...)",
          "type": "pubkeyhash",
          "address": {
            "str": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
          }
        }
      }
    ],
    "blockhash": "0000000000000bae09a7a393e0...",
    "confirmations": 536,
    "blocktime": 1611718263,
    "time": 1611718263
  },
  "error": null,
  "id": "curltest"
}

If verbose is unset or set to 0:

  • str: Returns the serialized, hex-encoded data corresponding to the 'txid'.

If verbose is set to 1 or 2:

  • in_active_chain: Indicates if the specified block is in the active chain (only available when 'blockhash' parameter is utilized).
  • hex: Serialized, hex-encoded data for the 'txid'.
  • txid: Identifies the transaction.
  • hash: The hash of the transaction (differs from txid for witness transactions).
  • size: Indicates the transaction size.
  • vsize: Represents the virtual transaction size (differs for witness transactions).
  • weight: Specifies the transaction weight, calculated between 'vsize*4 - 3' and 'vsize*4'.
  • version: Indicates the block version.
  • locktime: Represents the transaction locktime.
  • vin: A JSON array representing the input vectors of the transaction, comprising of:
    • txid: Transaction id.
    • vout: Output number.
    • scriptSig: Script's signature details, including:
      • asm: Script's public key as a string.
      • hex: Hex-encoded witness data.
    • sequence: Script's sequence number.
    • txinwitness: An array of JSON objects containing hex-encoded witness data.
  • vout: A JSON array with transaction output details, including:
    • value: Value in BTC.
    • n: Output index.
    • scriptPubKey: A JSON object with PubKey script information, encompassing:
      • asm: Script public key as a string.
      • hex: Hex representation of the script's public key.
      • desc: Inferred descriptor for the output.
      • type: Script type, such as pubkeyhash or multisig.
      • address: Details of the Bitcoin address, featuring:
        • str: Bitcoin address as a string.
  • blockhash: The hash of the block.
  • confirmations: The count of confirmed transactions in the block.
  • blocktime: Block time, represented in UNIX epoch time.
  • time: Echoes 'blocktime'.
Service StatusGitHub SDK