# Change library (https://037c9e19.docs-50g.pages.dev/llms/foundations/actions/change-library/content.md)



A smart contract can request a change to an account's library collection during the [action phase](https://037c9e19.docs-50g.pages.dev/llms/foundations/phases/content.md) via the change-library action. Any of these instructions can append the change-library action to an [out action list](https://github.com/ton-blockchain/ton/blob/5c0349110bb03dd3a241689f2ab334ae1a554ffb/crypto/block/block.tlb#L411):

* [`SETLIBCODE`](https://037c9e19.docs-50g.pages.dev/llms/tvm/instructions/content.md)
* [`CHANGELIB`](https://037c9e19.docs-50g.pages.dev/llms/tvm/instructions/content.md)
* [`POPCTR`](https://037c9e19.docs-50g.pages.dev/llms/tvm/instructions/content.md)

The change-library action contains:

* a 7-bit `mode` bitmask specifying the way of changing the library;
* a `LibRef` value containing either a cell reference to the library code or its hash as an unsigned 256-bit integer.

## Modes [#modes]

The `mode` bitmask supports the following values, with `BounceOnFail` allowed to be combined with any other value:

| Value | Name                | Description                                                                            |
| ----: | :------------------ | -------------------------------------------------------------------------------------- |
|   `0` | `RemoveLibrary`     | Default mode. Removes a public library if it exists, otherwise does nothing.           |
|  `+1` | `AddPrivateLibrary` | Sets the library status as private. Cannot be combined with `AddPublicLibrary` (`+2`). |
|  `+2` | `AddPublicLibrary`  | Sets the library status as public. Cannot be combined with `AddPrivateLibrary` (`+1`). |
| `+16` | `BounceOnFail`      | Bounces the transaction if the action fails.                                           |

Other mode values and their combinations are invalid. Using both `AddPrivateLibrary` (`+1`) and `AddPublicLibrary` (`+2`) modes at the same time is also invalid and leads to an error.

<Callout type="caution" title="Limited availability">
  Since global TVM version 15, the action phase returns [exit code `46`](https://037c9e19.docs-50g.pages.dev/llms/tvm/exit-codes/content.md) on mainnet and testnet when any account uses mode `AddPrivateLibrary` (`+1`) or when a regular account requests any library change. Only [special masterchain accounts](https://037c9e19.docs-50g.pages.dev/llms/foundations/config/content.md) can use base mode `0` or `+2` to remove or add public libraries.

  The [libraries reference page](https://037c9e19.docs-50g.pages.dev/llms/foundations/serialization/library/content.md) explains how this restriction affects their use.
</Callout>

## Serialization [#serialization]

```tlb
libref_hash$0 lib_hash:bits256 = LibRef;
libref_ref$1 library:^Cell = LibRef;
action_change_library#26fa1dd4
    mode:(## 7) libref:LibRef = OutAction;
```
