ton3-core / Cell
• new Cell(options?
)
Creates an instance of 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 ]
})
Name | Type |
---|---|
options? |
CellOptions |
• 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 ]
Bit
[]
• 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 ]
Cell
[]
• 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
• 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
• 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
boolean
▸ 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
Name | Type | Default value |
---|---|---|
level |
number |
3 |
string
▸ 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
Name | Type | Default value |
---|---|---|
level |
number |
3 |
number
▸ 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 ]
▸ 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{_}
Name | Type | Default value |
---|---|---|
indent |
number |
1 |
size |
number |
0 |
string
▸ 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
Name | Type |
---|---|
cell |
Cell |
boolean