For the complete documentation index, see llms.txt. This page is also available as Markdown.

decodescript - Bitcoin

Example code for the decodescript JSON-RPC method. Complete guide on how to use decodescript JSON-RPC in GetBlock Web3 documentation.

This method decodes a hex-encoded script and returns details about it, including its assembly, type, and the addresses it pays to.

Parameters

Parameter
Type
Required
Description

hexstring

string

Yes

The script hex

Request

curl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "decodescript",
    "params": ["76a914d0f172a0ecb48aee1be1f2687d2963ae33f71a1088ac"],
    "id": "getblock.io"
}'
example.js
const axios = require('axios');

const response = await axios.post('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/', {
    jsonrpc: '2.0',
    method: 'decodescript',
    params: ["76a914d0f172a0ecb48aee1be1f2687d2963ae33f71a1088ac"],
    id: 'getblock.io'
}, {
    headers: { 'Content-Type': 'application/json' }
});

console.log(response.data.result);
example.py
import requests

response = requests.post(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'decodescript',
        'params': ["76a914d0f172a0ecb48aee1be1f2687d2963ae33f71a1088ac"],
        'id': 'getblock.io'
    }
)

print(response.json())

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": {
        "asm": "OP_DUP OP_HASH160 d0f172a0ecb48aee1be1f2687d2963ae33f71a10 OP_EQUALVERIFY OP_CHECKSIG",
        "desc": "addr(bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq)#checksum",
        "type": "pubkeyhash",
        "address": "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
        "p2sh": "3P14159f73E4gFr7JterCCQh9QjiTjiZrG"
    }
}

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

object

Decoded script object

Result Object

Field
Type
Description

asm

string

Script in assembly notation

type

string

Output type (pubkeyhash, scripthash, witness_v0_keyhash, and others)

address

string

Address the script pays to, when applicable

p2sh

string

The P2SH address wrapping this script

Use Cases

  • Script Analysis: Understand a locking script

  • Address Derivation: Read the address a script encodes

  • Debugging: Inspect custom scripts

  • Tooling: Decode scripts in explorers

Error Handling

Error Code
Message
Description

403

Forbidden

Missing or invalid ACCESS-TOKEN

-22

Decode failed

The transaction or script could not be decoded

-8

Invalid parameter

A parameter is out of range or malformed

-32602

Invalid params

A parameter is missing or has the wrong type

Last updated

Was this helpful?