# `BSV.Script`
[🔗](https://github.com/Bittoku/bsv_sdk_elixir/blob/main/lib/bsv/script/script.ex#L1)

Bitcoin Script type — a sequence of opcodes and data pushes.

Scripts are used in transaction inputs (unlocking) and outputs (locking)
to define spending conditions.

# `chunk`

```elixir
@type chunk() :: {:op, byte()} | {:data, binary()}
```

# `t`

```elixir
@type t() :: %BSV.Script{chunks: [chunk()]}
```

# `from_asm`

```elixir
@spec from_asm(String.t()) :: {:ok, t()} | {:error, term()}
```

Parse a Bitcoin ASM string into a Script.

# `from_binary`

```elixir
@spec from_binary(binary()) :: {:ok, t()} | {:error, term()}
```

Parse a binary into a Script struct.

# `from_hex`

```elixir
@spec from_hex(String.t()) :: {:ok, t()} | {:error, term()}
```

Parse a hex string into a Script.

# `get_pubkey_hash`

```elixir
@spec get_pubkey_hash(t()) :: {:ok, &lt;&lt;_::160&gt;&gt;} | :error
```

Extract the public key hash from a P2PKH script.

# `is_op_return?`

```elixir
@spec is_op_return?(t()) :: boolean()
```

Check if a script is OP_RETURN data.

# `is_p2pkh?`

```elixir
@spec is_p2pkh?(t()) :: boolean()
```

Check if a script is P2PKH.

# `is_p2sh?`

```elixir
@spec is_p2sh?(t()) :: boolean()
```

Check if a script is P2SH (OP_HASH160 <20 bytes> OP_EQUAL).

# `new`

```elixir
@spec new() :: t()
```

Create a new empty script.

# `op_return`

```elixir
@spec op_return([binary()]) :: t()
```

Build an OP_RETURN data script (OP_FALSE OP_RETURN <data>...).

# `p2pkh_lock`

```elixir
@spec p2pkh_lock(&lt;&lt;_::160&gt;&gt;) :: t()
```

Build a P2PKH locking script from a 20-byte public key hash.

# `p2pkh_unlock`

```elixir
@spec p2pkh_unlock(binary(), binary()) :: t()
```

Build a P2PKH unlocking script from a signature and public key.

# `to_asm`

```elixir
@spec to_asm(t()) :: String.t()
```

Convert a script to its ASM string representation.

# `to_binary`

```elixir
@spec to_binary(t()) :: binary()
```

Serialize a script to raw bytes.

# `to_hex`

```elixir
@spec to_hex(t()) :: String.t()
```

Serialize a script to a hex string.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
