PHPackages                             amashukov/ton-cell-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. amashukov/ton-cell-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

amashukov/ton-cell-php
======================

TLB Cell / Builder / Slice / canonical BOC encoder for The Open Network in pure PHP — byte-exact equivalent of @ton/core's cell layer.

v0.1.0(2w ago)0224↑92.3%2MITPHPPHP &gt;=8.3CI failing

Since May 24Pushed 1w agoCompare

[ Source](https://github.com/AndreyMashukov/ton-cell-php)[ Packagist](https://packagist.org/packages/amashukov/ton-cell-php)[ RSS](/packages/amashukov-ton-cell-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (2)Used By (2)

amashukov/ton-cell-php
======================

[](#amashukovton-cell-php)

Pure-PHP TLB Cell, Builder, Slice and canonical BOC encoder for The Open Network (TON) — byte-for-byte parity with `@ton/core`.

[![CI](https://camo.githubusercontent.com/b91c344e7b9fa61d8cbd6ab094ffb636852a43edfbe26419363370c7bfa9a9a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416e647265794d617368756b6f762f746f6e2d63656c6c2d7068702f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d4349)](https://github.com/AndreyMashukov/ton-cell-php/actions)[![PHPStan L9](https://camo.githubusercontent.com/be6b6354c571da6a5dbc9b96a03fdecd3d79e34c45c740121c5564ab41aa0154/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f416e647265794d617368756b6f762f746f6e2d63656c6c2d7068702f7374616e2e796d6c3f6272616e63683d6d61696e266c6162656c3d5048505374616e2532304c39)](https://github.com/AndreyMashukov/ton-cell-php/actions)[![Latest Version](https://camo.githubusercontent.com/466eab2a14be01348f9ed059cbb0df8e22d8b702af27327cf699c7428443624b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d617368756b6f762f746f6e2d63656c6c2d706870)](https://packagist.org/packages/amashukov/ton-cell-php)[![Downloads](https://camo.githubusercontent.com/b8a35b037ed75540ac1064745883acb5c0a7163ff2ce2e1562c4e0e84578f941/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d617368756b6f762f746f6e2d63656c6c2d706870)](https://packagist.org/packages/amashukov/ton-cell-php)[![PHP](https://camo.githubusercontent.com/e78fc9a857f001daf466c505c6697312ad06ebf32919c332c911082655c1a2ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f616d617368756b6f762f746f6e2d63656c6c2d7068702f706870)](https://packagist.org/packages/amashukov/ton-cell-php)[![License](https://camo.githubusercontent.com/2c27dc6c3e0330441547a148b6289995ae8b10fe08a6ec94366f3c981cacdcf6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d617368756b6f762f746f6e2d63656c6c2d706870)](LICENSE)[![Stars](https://camo.githubusercontent.com/a8b0152329b8284b544e4d970b5d48235df802ae82158897429add4ca730ad24/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f416e647265794d617368756b6f762f746f6e2d63656c6c2d7068703f7374796c653d736f6369616c)](https://github.com/AndreyMashukov/ton-cell-php)

`amashukov/ton-cell-php` implements the TLB (Type Language - Binary) cell layer for The Open Network (TON) in pure PHP: `Cell`, `Builder`, `Slice`, and a canonical `BOC` (Bag of Cells) serializer. It is a byte-exact equivalent of the `@ton/core` cell layer used across TON SDKs, suitable for building and parsing jetton transfers, contract messages and any TLB-encoded payload from PHP.

Features
--------

[](#features)

- **`Builder`** — fluent cell construction: bits, unsigned/signed ints, coins, addresses, refs, string tails.
- **`Slice`** — TLB parser mirroring the builder surface.
- **Canonical `BOC` serializer** — emits `@ton/core` v15's canonical wire format (`has_crc32c=1`, little-endian CRC32C tail) with `offset_byte_size` auto-promotion from 1 to 2 when cell data exceeds 255 bytes.
- **Byte-for-byte parity** with `@ton/core` v15 — validated against upstream fixtures.
- **Big integers via `ext-gmp`** — values crossing `PHP_INT_MAX` flow in and out as decimal strings.
- **Cell hashing** — 32-byte SHA-256 of the recursive TLB representation for Ed25519 signing and address derivation.
- PHPStan level 9 clean, `@PER-CS` formatted, CI-tested.

Why amashukov/ton-cell-php
--------------------------

[](#why-amashukovton-cell-php)

TON SDKs are written in TypeScript (`@ton/core`) and a PHP project either shells out to Node or reimplements the cell layer ad hoc. `amashukov/ton-cell-php` gives you the cell / BOC primitives natively in PHP with byte-for-byte parity against `@ton/core` v15, so a BOC built in PHP is wire-identical to one built by the canonical SDK — no Node sidecar, no FFI.

Installation
------------

[](#installation)

```
composer require amashukov/ton-cell-php
```

Usage
-----

[](#usage)

### Build a cell

[](#build-a-cell)

```
use Amashukov\TonCell\AddressData;
use Amashukov\TonCell\Builder;

$cell = (new Builder())
    ->storeUint(0xF8A7EA5, 32)                       // jetton-transfer op
    ->storeUint(0xC0FFEE, 64)                        // query id
    ->storeCoins('1000000')                          // amount (decimal string for bigints)
    ->storeAddress(new AddressData(0, $hashPart32))  // destination
    ->endCell();
```

`Builder` exposes `storeBit`, `storeUint(int|string $value, int $bits)`, `storeInt`, `storeCoins`, `storeBits`, `storeBuffer`, `storeAddress`, `storeRef`, `storeStringTail`, `storeStringRefTail`, `storeBuilder`, `storeCellInline`. Bigint values cross `PHP_INT_MAX` safely via `ext-gmp` (decimal-string in, decimal-string out).

### Parse a cell

[](#parse-a-cell)

```
$slice = $cell->beginParse();

$op       = $slice->loadUint(32);                  // int when fitting, string for >PHP_INT_MAX
$queryId  = $slice->loadUint(64);
$amount   = $slice->loadCoins();                   // always decimal string
$dest     = $slice->loadAddress();                 // AddressData|null
```

`Slice` exposes `loadBit`, `loadUint`, `loadUintString`, `loadCoins`, `loadAddress`, `loadBits`, `loadRef`, `loadStringTail`, `loadStringRefTail`, `remainingBits`, `remainingRefs`. Anycast and non-`addr_std$10` shapes are rejected with `RuntimeException`.

### Compute the cell hash

[](#compute-the-cell-hash)

```
$hash = $cell->hash();   // 32-byte SHA-256 of the recursive TLB representation
$depth = $cell->maxDepth();
```

Used for Ed25519 message signing and TON address derivation. Memoised across calls.

### Serialise to BOC

[](#serialise-to-boc)

```
use Amashukov\TonCell\Boc;

$wireBytes  = Boc::encode($cell);          // canonical TON BOC bytes with CRC32C tail
$base64     = Boc::encodeBase64($cell);    // ready for toncenter /sendBoc
```

The BOC encoder emits `@ton/core` v15's canonical format (`has_crc32c=1`, little-endian CRC32C tail) and auto-promotes `offset_byte_size` from 1 to 2 when total cell-data size exceeds 255 bytes. Hard cap is 65 535 bytes per BOC; extend the encoder, not the rule.

### `AddressData` value object

[](#addressdata-value-object)

`AddressData` is a minimal `wc + hashPart` carrier — just enough for the cell layer to serialise the `addr_std$10` TLB shape. Full address parsing (user-friendly `EQ…` / `UQ…` base64 forms, CRC-16 checksum, testnet flag) belongs to a downstream wallet package and lives on top of this VO.

### `BitReader`

[](#bitreader)

Bit-level reader over a binary string with a known precise bit length — useful for parsing TLB fields that aren't byte-aligned (for example, contract-emitted event payloads). `readUint(bits)` and `readInt(bits)` cover `[0, 32]` with strict overrun + range guards.

Requirements
------------

[](#requirements)

- PHP 8.3+
- `ext-gmp`

No composer dependencies.

Related packages
----------------

[](#related-packages)

Part of a modular pure-PHP blockchain toolkit:

PackagePurpose[amashukov/ton-cell-php](https://github.com/AndreyMashukov/ton-cell-php)TON TLB Cell / Builder / Slice / BOC[amashukov/ton-crypto-php](https://github.com/AndreyMashukov/ton-crypto-php)TON Ed25519 / mnemonic crypto[amashukov/ton-wallet-php](https://github.com/AndreyMashukov/ton-wallet-php)TON wallet contract tooling[amashukov/toncenter-client-php](https://github.com/AndreyMashukov/toncenter-client-php)toncenter JSON-RPC client[amashukov/ton-php](https://github.com/AndreyMashukov/ton-php)TON umbrella package[amashukov/keccak-php](https://github.com/AndreyMashukov/keccak-php)Keccak-256 / SHA-3 / SHAKE hashing[amashukov/secp256k1-php](https://github.com/AndreyMashukov/secp256k1-php)secp256k1 ECDSA sign / verify / recover[amashukov/rlp-php](https://github.com/AndreyMashukov/rlp-php)Ethereum RLP encode / decodeQuality
-------

[](#quality)

- PHPStan level 9.
- php-cs-fixer with the `@PER-CS` ruleset.
- GitHub Actions CI on every push.
- Byte-for-byte parity tests against `@ton/core` v15 fixtures.

Reference
---------

[](#reference)

- TL-B language:
- Cell representation + BOC format:

License
-------

[](#license)

MIT License.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance98

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

17d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b3e86ca79a82515b23e0239b1d3616c747e59b64c40e169d538d5c759c9bbc4?d=identicon)[Andrey Mashukov](/maintainers/Andrey%20Mashukov)

---

Top Contributors

[![AndreyMashukov](https://avatars.githubusercontent.com/u/24682497?v=4)](https://github.com/AndreyMashukov "AndreyMashukov (4 commits)")

---

Tags

blockchainboccellphpthe-open-networktlbtonblockchainBOCtonthe open networkCelltlb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/amashukov-ton-cell-php/health.svg)

```
[![Health](https://phpackages.com/badges/amashukov-ton-cell-php/health.svg)](https://phpackages.com/packages/amashukov-ton-cell-php)
```

###  Alternatives

[olifanton/interop

Olifanton interop library

1071.8k3](/packages/olifanton-interop)[olifanton/ton

PHP library for The Open Network blockchain

9056.6k2](/packages/olifanton-ton)[paragonie/blakechain

Hash chain using BLAKE2b

242.9k3](/packages/paragonie-blakechain)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
