> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cowboy.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# cowboy lib

> Publish, remove, query, and copy CIP-26 account libraries

## Synopsis

```bash theme={null}
cowboy lib publish --name <str> --code <path> [--private-key <path>] [--rpc-url <url>]
cowboy lib remove --name <str> [--private-key <path>] [--rpc-url <url>]
cowboy lib list --publisher <address> --name <str> [--rpc-url <url>]
cowboy lib copy --from <address> --name <str> --expected-hash <hex> [--private-key <path>] [--rpc-url <url>]
```

`cowboy lib` manages the [CIP-26](https://docs.cowboy.inc/cips/cip-26-account-libraries.md) library catalog: Python source files published under a publisher account so that actors can import them by `(publisher, name)`.

`--rpc-url` and `--private-key` are global flags. The RPC URL resolves like any command's (`--rpc-url`, then `COWBOY_RPC_URL`, then the selected environment's endpoint, then `http://localhost:4000`); the private key uses [key auto-discovery](https://docs.cowboy.inc/cli-specs/key-auto-discovery.md).

## Subcommands

### `cowboy lib publish`

Publish (or update) a library under the signer's publisher address.

**Behavior:**

1. Validate the name: 1--64 ASCII bytes matching `^[A-Za-z_][A-Za-z0-9_]*$`.
2. Read the source file.
3. Load the private key using [key auto-discovery](https://docs.cowboy.inc/cli-specs/key-auto-discovery.md).
4. Size the transaction's gas from the source length (200 base cycles + 22 cycles/byte; 41 cells/byte; each padded 25%, floor 200,000). A source over 131,072 bytes is rejected before signing.
5. Sign and submit `PublishLibrary`.

**Flags:**

| Flag | Default | Description |
| - | - | - |
| `--name` | Required | Library name (1--64 ASCII bytes, `^[A-Za-z_][A-Za-z0-9_]*$`) |
| `--code` | Required | Path to the library Python source file |
| `--private-key` | Auto-discovered | Private key file path, or set `COWBOY_PRIVATE_KEY` |
| `--rpc-url` | Auto-discovered | RPC endpoint (global flag); env `COWBOY_RPC_URL` |

**Example:**

```bash theme={null}
$ cowboy lib publish --name eth_utils --code libs/eth_utils.py
```

Output is the transaction submission summary (see `--help`).

***

### `cowboy lib remove`

Remove a library under the signer's publisher address. Non-idempotent: removing a missing library fails with `LibraryNotFound`.

**Flags:**

| Flag | Default | Description |
| - | - | - |
| `--name` | Required | Library name (1--64 ASCII bytes) |
| `--private-key` | Auto-discovered | Private key file path, or set `COWBOY_PRIVATE_KEY` |
| `--rpc-url` | Auto-discovered | RPC endpoint (global flag); env `COWBOY_RPC_URL` |

***

### `cowboy lib list`

Query a library's catalog entry. Read-only; no private key.

**Behavior:**

1. `GET {rpc_url}/library/0x{publisher}/{name}`.
2. On success print the JSON entry. On `404` print `Library not found` and exit `1`.

**Flags:**

| Flag | Default | Description |
| - | - | - |
| `--publisher` | Required | Publisher address (hex) |
| `--name` | Required | Library name |
| `--rpc-url` | Auto-discovered | RPC endpoint (global flag); env `COWBOY_RPC_URL` |

**Example:**

```bash theme={null}
$ cowboy lib list --publisher 0x7a3B...F92E --name eth_utils
{
  "code_hash": "0x...",
  ...
}
```

***

### `cowboy lib copy`

Fetch a library from another publisher, verify its hash locally, and republish the audited bytes under your own publisher account. No new chain instruction is used; this is a client-side helper that ends in an ordinary `PublishLibrary`.

**Behavior:**

1. Parse `--expected-hash` (32-byte keccak256, `0x` optional).
2. `GET /library/0x{from}/{name}` for the metadata, then `GET /code/{code_hash}` for the bytes.
3. Compute `keccak256(code_bytes)`. On mismatch print `Hash mismatch! ... NOT sending transaction.` and exit `1`.
4. Validate the name, load the private key, and submit `PublishLibrary` with the verified bytes.
5. Print `Copied library (hash verified)`.

**Flags:**

| Flag | Default | Description |
| - | - | - |
| `--from` | Required | Source publisher address (hex) |
| `--name` | Required | Library name to copy |
| `--expected-hash` | Required | Expected `keccak256(code_bytes)` (hex, `0x` optional) |
| `--private-key` | Auto-discovered | Private key file path, or set `COWBOY_PRIVATE_KEY` |
| `--rpc-url` | Auto-discovered | RPC endpoint (global flag); env `COWBOY_RPC_URL` |

**Example:**

```bash theme={null}
$ cowboy lib copy --from 0x5e6F...A7B8 --name eth_utils --expected-hash 0x9c0d...
Copied library (hash verified)
```

## Edge Cases

* Names that are empty, longer than 64 bytes, non-ASCII, start with a digit, or contain a hyphen are rejected locally.
* `remove` on a missing library fails on chain with `LibraryNotFound`.
* `list` exits `1` on a `404`; `copy` exits `1` on a hash mismatch and sends no transaction.
* The largest publishable source is 131,072 bytes (the codec's library cap, which binds before the User-lane limit). Larger sources are rejected before signing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.