BitcoinMethods

Decodescript

The decodescript RPC method allows you to decode a hex-encoded script, facilitating a deeper understanding of the script's structure and components. Each call to this method will consume 1 API credit.

Decodescript

Overview

The decodescript RPC method allows you to decode a hex-encoded script, facilitating a deeper understanding of the script's structure and components. Each call to this method will consume 1 API credit.

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": "1.0",
  "id": "1",
  "method": "Decodescript",
  "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("{\r\n  \"jsonrpc\": \"1.0\",\r\n  \"id\": \"1\",\r\n  \"method\": \"Decodescript\",\r\n  \"params\": []\r\n}\r\n", 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": "1.0",
  "id": "1",
  "method": "Decodescript",
  "params": []
}';
$request = new Request('POST', 'https://bitcoin-mainnet.node.coinapi.io', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
?>

python

import requests
import json

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

payload = json.dumps({
  "jsonrpc": "1.0",
  "id": "1",
  "method": "Decodescript",
  "params": []
})
headers = {
  'Content-Type': 'application/json',
  'accept': 'application/json',
  'X-CoinAPI-Key': '73034021-THIS-IS-SAMPLE-KEY'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

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": "1.0",
    "id": "1",
    "method": "Decodescript",
    "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": "1.0",`+"
"+`
  "id": "1",`+"
"+`
  "method": "Decodescript",`+"
"+`
  "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": "1.0",
  "id": "1",
  "method": "Decodescript",
  "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, "{\r\n \"jsonrpc\": \"1.0\",\r\n \"id\": \"1\",\r\n \"method\": \"Decodescript\",\r\n \"params\": []\r\n}\r\n");
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();

Parameters

'hexstring' (required)

  • Type: string
  • Description: The hex-encoded script that needs to be decoded.

Returns

The method returns an object with the following properties:

'asm'

  • Type: string
  • Description: Represents the script public key in a string format.

type

  • Type: string
  • Description: Specifies the output type. It can be one of the following: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash, witness_v0_keyhash, witness_v1_taproot, or witness_unknown.

reqSigs

  • Type: integer
  • Description: Indicates the number of required signatures.

addresses

  • Type: JSON array
  • Description: A JSON array containing the addresses involved in the transaction.

str

  • Type: string
  • Description: The Bitcoin address associated with the script.

p2sh

  • type: string (optional)
  • Description: The address of the P2SH script that wraps this redeem script. This field is not returned if the script is already a P2SH.

segwit

  • Type: object (optional)

  • Description: Contains information about the witness script public key that wraps this redeem script. This field is not returned if the script is a P2SH or witness. The object contains the following properties:

    • 'asm': The script public key in string format.
    • 'hex': The hex representation of the script's public key in string format.
    • 'type': The type of the script public key.
    • 'reqSigs': The number of required signatures.
    • 'addresses': A JSON array of addresses involved.
    • 'str': The segwit address.
    • 'p2sh-segwit': The address of the P2SH script wrapping this witness redeem script.
Service StatusGitHub SDK