# decodescript

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://bitcoin-mainnet.g.alchemy.com/v2/{apiKey}

Decodes a hex-encoded script and provides detailed information about it.


Reference: https://www.alchemy.com/docs/chains/bitcoin/bitcoin-api-endpoints/decodescript

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| hexstring | string | Yes | The hex-encoded script. |

## Result

**result** (object): Decoded script information.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "decodescript",
  "params": [
    "0014751e76e8199196d454941c45d1b3a323f1433bd6"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "asm": "0 751e76e8199196d454941c45d1b3a323f1433bd6",
    "desc": "addr(bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4)#uyjndxcw",
    "address": "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
    "type": "witness_v0_keyhash",
    "p2sh": "3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN"
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "decodescript",
  "params": [
    "0014751e76e8199196d454941c45d1b3a323f1433bd6"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'decodescript',
    params: ['0014751e76e8199196d454941c45d1b3a323f1433bd6']
  })
};

fetch('https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "decodescript",
    "params": ["0014751e76e8199196d454941c45d1b3a323f1433bd6"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

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

func main() {

	url := "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"decodescript\",\n  \"params\": [\n    \"0014751e76e8199196d454941c45d1b3a323f1433bd6\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"decodescript\",\n  \"params\": [\n    \"0014751e76e8199196d454941c45d1b3a323f1433bd6\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"decodescript\",\n  \"params\": [\n    \"0014751e76e8199196d454941c45d1b3a323f1433bd6\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: decodescript
summary: Decode a hex-encoded script
description: |
  Decodes a hex-encoded script and provides detailed information about it.
params:
  - name: hexstring
    required: true
    description: The hex-encoded script.
    schema:
      title: Hex-encoded Script
      type: string
      pattern: ^[a-fA-F0-9]+$
      description: A hex-encoded script for use in decoding.
result:
  name: result
  description: Decoded script information.
  schema:
    type: object
    properties:
      asm:
        type: string
        description: The script public key in assembly form.
      desc:
        type: string
        description: Output descriptor for the script.
      address:
        type: string
        description: The derived Bitcoin address (if applicable).
      type:
        type: string
        description: Output type (e.g., nonstandard, pubkeyhash, scripthash, witness_v0_keyhash).
      p2sh:
        type: string
        description: P2SH address wrapping this script, if applicable.
examples:
  - name: decodescript example
    params:
      - name: hexstring
        value: 0014751e76e8199196d454941c45d1b3a323f1433bd6
    result:
      name: result
      value:
        asm: 0 751e76e8199196d454941c45d1b3a323f1433bd6
        desc: addr(bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4)#uyjndxcw
        address: bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
        type: witness_v0_keyhash
        p2sh: 3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN
```
