Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Latest commit

 

History

History
302 lines (187 loc) · 4.72 KB

Cell.md

File metadata and controls

302 lines (187 loc) · 4.72 KB

ton3-core / Cell

Class: Cell

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new Cell(options?)

Creates an instance of Cell

  • You should avoid creating Cell manually
  • Use Builder to construct your Cell

example

import { Cell, CellType } from 'ton3-core'

const ref = new Cell()
const cell = new Cell({
    type: CellType.Ordinary,
    bits: [ 1, 0, 1 ],
    refs: [ ref ]
})

Parameters

Name Type
options? CellOptions

Accessors

bits

get bits(): Bit[]

Get current Cell instance bits

example

import { Builder } from 'ton3-core'

const cell = new Builder().storeBits([ 1, 0 ])

console.log(cell.bits) // [ 1, 0 ]

Returns

Bit[]


refs

get refs(): Cell[]

Get current Cell instance refs

example

import { Builder } from 'ton3-core'

const ref = new Builder().cell()
const cell = new Builder().storeRef(ref)

console.log(cell.refs) // [ ref ]

Returns

Cell[]


mask

get mask(): Mask

Get current Cell instance Mask (that includes level, hashes count, etc...)

example

import { Builder } from 'ton3-core'

const cell = new Builder().cell()

console.log(cell.mask.level) // 0
console.log(cell.mask.hashCount) // 1

Returns

Mask


type

get type(): CellType

Get current Cell instance CellType

example

import { CellType, Builder } from 'ton3-core'

const cell = new Builder().cell()

console.log(cell.type === CellType.Ordinary) // true

Returns

CellType


exotic

get exotic(): boolean

Check if current Cell instance is exotic type

example

import { CellType, Builder, Bit } from 'ton3-core'

const zeroes = Array.from({ length: 8 + 256}).fill(0) as Bit[]
const cell1 = new Builder().cell(CellType.Ordinary)
const cell2 = new Builder().storeBits(zeroes).cell(CellType.LibraryReference)

console.log(cell1.exotic) // false
console.log(cell2.exotic) // true

Returns

boolean

Methods

hash

hash(level?): string

Get cell's hash in hex (max level by default)

example

import { Builder } from 'ton3-core'

const cell = new Builder().cell()

console.log(cell.hash()) // 96a296d224f285c67bee93c30f8a309157f0daa35dc5b87e410b78630a09cfc7

Parameters

Name Type Default value
level number 3

Returns

string


depth

depth(level?): number

Get cell's depth (max level by default)

example

import { Builder } from 'ton3-core'

const cell1 = new Builder().cell()
const cell2 = new Builder().storeRef(cell1).cell()

console.log(cell2.depth()) // 1

Parameters

Name Type Default value
level number 3

Returns

number


slice

slice(): Slice

Get Slice from current instance

  • Same as Slice.parse(cell)

example

import { Builder } from 'ton3-core'

const cell = new Builder()
    .storeBits([ 1, 0 ])
    .cell()

const slice = cell.slice()

console.log(slice.loadBits(2)) // [ 1, 0 ]
console.log(cell.bits) // [ 1, 0 ]

Returns

Slice


print

print(indent?, size?): string

Print cell as fift-hex

example

import { Builder } from 'ton3-core'

const cell = new Builder().cell()

console.log(cell.print()) // x{_}

Parameters

Name Type Default value
indent number 1
size number 0

Returns

string


eq

eq(cell): boolean

Checks Cell equality by comparing cell hashes

example

import { Builder } from 'ton3-core'

const cell = new Builder().storeBits([ 1, 0 ]).cell()
const equal = new Builder().storeBits([ 1, 0 ]).cell()
const notEqual = new Builder().storeBits([ 0, 1 ]).cell()

console.log(equal.eq(cell), notEqual.eq(cell)) // true, false

Parameters

Name Type
cell Cell

Returns

boolean