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

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.ton.org/feedback

```json
{
  "path": "/foundations/actions/change-library",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Change library

Change a library is one of the actions that a smart contract can perform during the [action phase](/foundations/phases#action-phase). It adds libraries to or removes them from the collection of libraries of this smart contract. It can be appended to an [out action list](https://github.com/ton-blockchain/ton/blob/5c0349110bb03dd3a241689f2ab334ae1a554ffb/crypto/block/block.tlb#L411) by:

* The [`SETLIBCODE`](/tvm/instructions#fb06-setlibcode) instruction.
* The [`CHANGELIB`](/tvm/instructions#fb07-changelib) instruction.
* The [`POPCTR`](/tvm/instructions#ed5-popctr) instruction.

The change library action consists of

* a 7-bit bitmask `mode` specifying the way of changing the library;
* a ref to a cell containing the new library code or the hash of this code as an unsigned 256-bit integer.

## Modes

The `mode` can have the following values that can be combined together:

| Mode value | Convenient name     | Description                                                                                                                                                                                                                              |
| ---------: | :------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|        `0` | `RemoveLibrary`     | Default mode. Removes library if it was in the collection. Otherwise, action does nothing.                                                                                                                                               |
|       `+1` | `AddPrivateLibrary` | A library is added as a private library.                                                                                                                                                                                                 |
|       `+2` | `AddPublicLibrary`  | A library is added as a public library and becomes available to all smart contracts in all workchains if the current smart contract resides in the masterchain. If current contract is in other workchain, works as `AddPrivateLibrary`. |
|      `+16` | `BounceOnFail`      | Bounces the transaction if the action fails.                                                                                                                                                                                             |

The other values of `mode` are invalid and lead to an error. Simultaneous usage of the `AddPrivateLibrary` and `AddPublicLibrary` modes also leads to an error. If the library was present in the collection before, its public/private status is changed according to the `mode`.

## Serialization

```tlb theme={"theme":{"light":"github-light-default","dark":"dark-plus"},"languages":{"custom":["/resources/grammars/tolk.tmLanguage.json","/resources/grammars/tlb.tmLanguage.json","/resources/grammars/fift.tmLanguage.json","/resources/grammars/tasm.tmLanguage.json","/resources/grammars/func.tmLanguage.json"]}}
libref_hash$0 lib_hash:bits256 = LibRef;
libref_ref$1 library:^Cell = LibRef;
action_change_library#26fa1dd4 mode:(## 7)
    libref:LibRef = OutAction;
```
