On-chain libraries let the TON blockchain store contract code once on the masterchain and reuse it across multiple contracts, cutting storage costs compared to embedding the same bytecode in every account. Acton providesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ton-blockchain/acton/llms.txt
Use this file to discover all available pages before exploring further.
acton library commands to publish, inspect, top up, and fetch libraries, plus libraries.toml for tracking deployed library metadata locally. This page covers the full publishing workflow and how to reference deployed libraries from contracts in Acton.toml.
How on-chain libraries work
A library is a smart contract account on the masterchain that stores a code cell. When a contract useslibrary_ref as its dependency kind, the generated helper function produces a library reference cell (a 2-bit tag plus the code hash) instead of embedding the full bytecode. The TVM resolves the reference at execution time by looking up the hash in the masterchain library dictionary. Contracts pay only for the storage of the reference, not the full code.
Libraries are always stored on the masterchain (workchain -1) to remain accessible from all workchains.
Publishing a library
Step 1: Create the contract
Write the Tolk source file and register it inActon.toml:
contracts/Math.tolk
Acton.toml
Step 2: Publish
On success, Acton prints the library hash:
Non-interactive publish
--local or --global to save the library entry to libraries.toml or global.libraries.toml without an interactive prompt.
Monitoring library status
After publishing, monitor the library balance so storage fees do not drain and freeze the account:- Balance — current balance of the library account.
- Last top-up — timestamp used as the reference for storage runway calculations.
- Remaining — estimated storage runway based on current masterchain storage prices.
- Hash and account — the library hash and on-chain address.
Topping up a library
When the balance runs low, top up withacton library topup:
last_topup_timestamp field in library metadata.
Fetching a library
Inspect an existing library by hash:The libraries.toml file
Acton tracks deployed libraries inlibraries.toml (local) or global.libraries.toml (global). Each entry records the name, hash, code, account address, and storage metadata:
libraries.toml
acton init manages a global.libraries.toml symlink in the project root, similar to how it handles global wallets.
Referencing libraries from contracts
To use a published library as a dependency, switch the dependency kind tolibrary_ref in Acton.toml:
Acton.toml
gen/ instead of embedding the full code:
gen/Math.code.tolk
| Dependency kind | Code in parent | Library must be deployed |
|---|---|---|
embed_code (default) | Full bytecode embedded at compile time | No |
library_ref | 33-byte hash reference only | Yes |
Using libraries in tests and scripts
Acton exposes helpers for libraries in the standard library:tests/Jetton.test.tolk
net.loadLibrary(hash)— loads a library by hash and returns its code cell, ornullif not found.testing.registerLibrary(ref, code)— registers a library in the current test blockchain.testing.loadAndRegisterLibrary(hash)— fetches by hash and registers, returningtrueon success.
Deduplication
The TON masterchain deduplicates library cells by code hash. Publishing the same code twice does not create a second account — the hash is identical, so the existing library account is reused. Theacton library publish command checks for this and warns before sending a duplicate transaction.
Cost considerations
Storage fees accumulate
Libraries pay ongoing masterchain storage fees. Budget for the full intended lifetime when publishing, and monitor balance regularly.
Amortize over many contracts
The storage savings from
library_ref pay off when many contracts reference the same library. For a single contract, embed_code is simpler.Publish on mainnet carefully
Library publication transfers real TON and creates a permanent masterchain account. Test with the same contract on testnet first.
Top up before expiry
A library that runs out of storage budget is frozen. Frozen libraries cause all referencing contracts to fail at runtime. Set a calendar reminder to top up.