Links

Module boc

Module boc

BOC manipulation module.

Functions

decode_tvc – Decodes tvc according to the tvc spec. Read more about tvc structure here https://github.com/tonlabs/ever-struct/blob/main/src/scheme/mod.rs#L30
parse_message – Parses message boc into a JSON
parse_transaction – Parses transaction boc into a JSON
parse_account – Parses account boc into a JSON
parse_block – Parses block boc into a JSON
parse_shardstate – Parses shardstate boc into a JSON
get_blockchain_config – Extract blockchain configuration from key block and also from zerostate.
get_boc_hash – Calculates BOC root hash
get_boc_depth – Calculates BOC depth
get_code_from_tvc – Extracts code from TVC contract image
cache_get – Get BOC from cache
cache_set – Save BOC into cache or increase pin counter for existing pinned BOC
cache_unpin – Unpin BOCs with specified pin defined in the cache_set. Decrease pin reference counter for BOCs with specified pin defined in the cache_set. BOCs which have only 1 pin and its reference counter become 0 will be removed from cache
encode_boc – Encodes bag of cells (BOC) with builder operations. This method provides the same functionality as Solidity TvmBuilder. Resulting BOC of this method can be passed into Solidity and C++ contracts as TvmCell type.
get_code_salt – Returns the contract code's salt if it is present.
set_code_salt – Sets new salt to contract code.
decode_state_init – Decodes contract's initial state into code, data, libraries and special options.
encode_state_init – Encodes initial contract state from code, data, libraries ans special options (see input params)
encode_external_in_message – Encodes a message
get_compiler_version – Returns the compiler version used to compile the code.

Types

BocCacheTypePinnedVariant – Pin the BOC with pin name.
BocCacheTypeUnpinnedVariant – BOC is placed into a common BOC pool with limited size regulated by LRU (least recently used) cache lifecycle.
BuilderOpIntegerVariant – Append integer to cell data.
BuilderOpBitStringVariant – Append bit string to cell data.
BuilderOpCellVariant – Append ref to nested cells.
BuilderOpCellBocVariant – Append ref to nested cell.
BuilderOpAddressVariant – Address.
BuilderOp – Cell builder operation.
Tvc
TvcV1

Functions

decode_tvc

Decodes tvc according to the tvc spec. Read more about tvc structure here https://github.com/tonlabs/ever-struct/blob/main/src/scheme/mod.rs#L30
type ParamsOfDecodeTvc = {
tvc: string
}
type ResultOfDecodeTvc = {
tvc: Tvc
}
function decode_tvc(
params: ParamsOfDecodeTvc,
): Promise<ResultOfDecodeTvc>;
function decode_tvc_sync(
params: ParamsOfDecodeTvc,
): ResultOfDecodeTvc;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • tvc: string – Contract TVC BOC encoded as base64 or BOC handle

Result

  • tvc: Tvc – Decoded TVC

parse_message

Parses message boc into a JSON
JSON structure is compatible with GraphQL API message object
type ParamsOfParse = {
boc: string
}
type ResultOfParse = {
parsed: any
}
function parse_message(
params: ParamsOfParse,
): Promise<ResultOfParse>;
function parse_message_sync(
params: ParamsOfParse,
): ResultOfParse;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_transaction

Parses transaction boc into a JSON
JSON structure is compatible with GraphQL API transaction object
type ParamsOfParse = {
boc: string
}
type ResultOfParse = {
parsed: any
}
function parse_transaction(
params: ParamsOfParse,
): Promise<ResultOfParse>;
function parse_transaction_sync(
params: ParamsOfParse,
): ResultOfParse;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_account

Parses account boc into a JSON
JSON structure is compatible with GraphQL API account object
type ParamsOfParse = {
boc: string
}
type ResultOfParse = {
parsed: any
}
function parse_account(
params: ParamsOfParse,
): Promise<ResultOfParse>;
function parse_account_sync(
params: ParamsOfParse,
): ResultOfParse;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_block

Parses block boc into a JSON
JSON structure is compatible with GraphQL API block object
type ParamsOfParse = {
boc: string
}
type ResultOfParse = {
parsed: any
}
function parse_block(
params: ParamsOfParse,
): Promise<ResultOfParse>;
function parse_block_sync(
params: ParamsOfParse,
): ResultOfParse;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64

Result

  • parsed: any – JSON containing parsed BOC

parse_shardstate

Parses shardstate boc into a JSON
JSON structure is compatible with GraphQL API shardstate object
type ParamsOfParseShardstate = {
boc: string,
id: string,
workchain_id: number
}
type ResultOfParse = {
parsed: any
}
function parse_shardstate(
params: ParamsOfParseShardstate,
): Promise<ResultOfParse>;
function parse_shardstate_sync(
params: ParamsOfParseShardstate,
): ResultOfParse;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64
  • id: string – Shardstate identifier
  • workchain_id: number – Workchain shardstate belongs to

Result

  • parsed: any – JSON containing parsed BOC

get_blockchain_config

Extract blockchain configuration from key block and also from zerostate.
type ParamsOfGetBlockchainConfig = {
block_boc: string
}
type ResultOfGetBlockchainConfig = {
config_boc: string
}
function get_blockchain_config(
params: ParamsOfGetBlockchainConfig,
): Promise<ResultOfGetBlockchainConfig>;
function get_blockchain_config_sync(
params: ParamsOfGetBlockchainConfig,
): ResultOfGetBlockchainConfig;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • block_boc: string – Key block BOC or zerostate BOC encoded as base64

Result

  • config_boc: string – Blockchain config BOC encoded as base64

get_boc_hash

Calculates BOC root hash
type ParamsOfGetBocHash = {
boc: string
}
type ResultOfGetBocHash = {
hash: string
}
function get_boc_hash(
params: ParamsOfGetBocHash,
): Promise<ResultOfGetBocHash>;
function get_boc_hash_sync(
params: ParamsOfGetBocHash,
): ResultOfGetBocHash;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64 or BOC handle

Result

  • hash: string – BOC root hash encoded with hex

get_boc_depth

Calculates BOC depth
type ParamsOfGetBocDepth = {
boc: string
}
type ResultOfGetBocDepth = {
depth: number
}
function get_boc_depth(
params: ParamsOfGetBocDepth,
): Promise<ResultOfGetBocDepth>;
function get_boc_depth_sync(
params: ParamsOfGetBocDepth,
): ResultOfGetBocDepth;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64 or BOC handle

Result

  • depth: number – BOC root cell depth

get_code_from_tvc

Extracts code from TVC contract image
type ParamsOfGetCodeFromTvc = {
tvc: string
}
type ResultOfGetCodeFromTvc = {
code: string
}
function get_code_from_tvc(
params: ParamsOfGetCodeFromTvc,
): Promise<ResultOfGetCodeFromTvc>;
function get_code_from_tvc_sync(
params: ParamsOfGetCodeFromTvc,
): ResultOfGetCodeFromTvc;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • tvc: string – Contract TVC image or image BOC handle

Result

  • code: string – Contract code encoded as base64

cache_get

Get BOC from cache
type ParamsOfBocCacheGet = {
boc_ref: string
}
type ResultOfBocCacheGet = {
boc?: string
}
function cache_get(
params: ParamsOfBocCacheGet,
): Promise<ResultOfBocCacheGet>;
function cache_get_sync(
params: ParamsOfBocCacheGet,
): ResultOfBocCacheGet;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc_ref: string – Reference to the cached BOC

Result

  • boc?: string – BOC encoded as base64.

cache_set

Save BOC into cache or increase pin counter for existing pinned BOC
type ParamsOfBocCacheSet = {
boc: string,
cache_type: BocCacheType
}
type ResultOfBocCacheSet = {
boc_ref: string
}
function cache_set(
params: ParamsOfBocCacheSet,
): Promise<ResultOfBocCacheSet>;
function cache_set_sync(
params: ParamsOfBocCacheSet,
): ResultOfBocCacheSet;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • boc: string – BOC encoded as base64 or BOC reference
  • cache_type: BocCacheType – Cache type

Result

  • boc_ref: string – Reference to the cached BOC

cache_unpin

Unpin BOCs with specified pin defined in the cache_set. Decrease pin reference counter for BOCs with specified pin defined in the cache_set. BOCs which have only 1 pin and its reference counter become 0 will be removed from cache
type ParamsOfBocCacheUnpin = {
pin: string,
boc_ref?: string
}
function cache_unpin(
params: ParamsOfBocCacheUnpin,
): Promise<void>;
function cache_unpin_sync(
params: ParamsOfBocCacheUnpin,
): void;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • pin: string – Pinned name
  • boc_ref?: string – Reference to the cached BOC. If it is provided then only referenced BOC is unpinned

encode_boc

Encodes bag of cells (BOC) with builder operations. This method provides the same functionality as Solidity TvmBuilder. Resulting BOC of this method can be passed into Solidity and C++ contracts as TvmCell type.
type ParamsOfEncodeBoc = {
builder: BuilderOp[],
boc_cache?: BocCacheType
}
type ResultOfEncodeBoc = {
boc: string
}
function encode_boc(
params: ParamsOfEncodeBoc,
): Promise<ResultOfEncodeBoc>;
function encode_boc_sync(
params: ParamsOfEncodeBoc,
): ResultOfEncodeBoc;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • builder: BuilderOp[] – Cell builder operations.
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

Result

  • boc: string – Encoded cell BOC or BOC cache key.

get_code_salt

Returns the contract code's salt if it is present.
type ParamsOfGetCodeSalt = {
code: string,
boc_cache?: BocCacheType
}
type ResultOfGetCodeSalt = {
salt?: string
}
function get_code_salt(
params: ParamsOfGetCodeSalt,
): Promise<ResultOfGetCodeSalt>;
function get_code_salt_sync(
params: ParamsOfGetCodeSalt,
): ResultOfGetCodeSalt;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • code: string – Contract code BOC encoded as base64 or code BOC handle
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

Result

  • salt?: string – Contract code salt if present. BOC encoded as base64 or BOC handle

set_code_salt

Sets new salt to contract code.
Returns the new contract code with salt.
type ParamsOfSetCodeSalt = {
code: string,
salt: string,
boc_cache?: BocCacheType
}
type ResultOfSetCodeSalt = {
code: string
}
function set_code_salt(
params: ParamsOfSetCodeSalt,
): Promise<ResultOfSetCodeSalt>;
function set_code_salt_sync(
params: ParamsOfSetCodeSalt,
): ResultOfSetCodeSalt;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • code: string – Contract code BOC encoded as base64 or code BOC handle
  • salt: string – Code salt to set. BOC encoded as base64 or BOC handle
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

Result

  • code: string – Contract code with salt set. BOC encoded as base64 or BOC handle

decode_state_init

Decodes contract's initial state into code, data, libraries and special options.
type ParamsOfDecodeStateInit = {
state_init: string,
boc_cache?: BocCacheType
}
type ResultOfDecodeStateInit = {
code?: string,
code_hash?: string,
code_depth?: number,
data?: string,
data_hash?: string,
data_depth?: number,
library?: string,
tick?: boolean,
tock?: boolean,
split_depth?: number,
compiler_version?: string
}
function decode_state_init(
params: ParamsOfDecodeStateInit,
): Promise<ResultOfDecodeStateInit>;
function decode_state_init_sync(
params: ParamsOfDecodeStateInit,
): ResultOfDecodeStateInit;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • state_init: string – Contract StateInit image BOC encoded as base64 or BOC handle
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

Result

  • code?: string – Contract code BOC encoded as base64 or BOC handle
  • code_hash?: string – Contract code hash
  • code_depth?: number – Contract code depth
  • data?: string – Contract data BOC encoded as base64 or BOC handle
  • data_hash?: string – Contract data hash
  • data_depth?: number – Contract data depth
  • library?: string – Contract library BOC encoded as base64 or BOC handle
  • tick?: booleanspecial.tick field. Specifies the contract ability to handle tick transactions
  • tock?: booleanspecial.tock field. Specifies the contract ability to handle tock transactions
  • split_depth?: number – Is present and non-zero only in instances of large smart contracts
  • compiler_version?: string – Compiler version, for example 'sol 0.49.0'

encode_state_init

Encodes initial contract state from code, data, libraries ans special options (see input params)
type ParamsOfEncodeStateInit = {
code?: string,
data?: string,
library?: string,
tick?: boolean,
tock?: boolean,
split_depth?: number,
boc_cache?: BocCacheType
}
type ResultOfEncodeStateInit = {
state_init: string
}
function encode_state_init(
params: ParamsOfEncodeStateInit,
): Promise<ResultOfEncodeStateInit>;
function encode_state_init_sync(
params: ParamsOfEncodeStateInit,
): ResultOfEncodeStateInit;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • code?: string – Contract code BOC encoded as base64 or BOC handle
  • data?: string – Contract data BOC encoded as base64 or BOC handle
  • library?: string – Contract library BOC encoded as base64 or BOC handle
  • tick?: booleanspecial.tick field. Specifies the contract ability to handle tick transactions
  • tock?: booleanspecial.tock field. Specifies the contract ability to handle tock transactions
  • split_depth?: number – Is present and non-zero only in instances of large smart contracts
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided.

Result

  • state_init: string – Contract StateInit image BOC encoded as base64 or BOC handle of boc_cache parameter was specified

encode_external_in_message

Encodes a message
Allows to encode any external inbound message.
type ParamsOfEncodeExternalInMessage = {
src?: string,
dst: string,
init?: string,
body?: string,
boc_cache?: BocCacheType
}
type ResultOfEncodeExternalInMessage = {
message: string,
message_id: string
}
function encode_external_in_message(
params: ParamsOfEncodeExternalInMessage,
): Promise<ResultOfEncodeExternalInMessage>;
function encode_external_in_message_sync(
params: ParamsOfEncodeExternalInMessage,
): ResultOfEncodeExternalInMessage;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • src?: string – Source address.
  • dst: string – Destination address.
  • init?: string – Bag of cells with state init (used in deploy messages).
  • body?: string – Bag of cells with the message body encoded as base64.
  • boc_cache?: BocCacheType – Cache type to put the result. The BOC itself returned if no cache type provided

Result

  • message: string – Message BOC encoded with base64.
  • message_id: string – Message id.

get_compiler_version

Returns the compiler version used to compile the code.
type ParamsOfGetCompilerVersion = {
code: string
}
type ResultOfGetCompilerVersion = {
version?: string
}
function get_compiler_version(
params: ParamsOfGetCompilerVersion,
): Promise<ResultOfGetCompilerVersion>;
function get_compiler_version_sync(
params: ParamsOfGetCompilerVersion,
): ResultOfGetCompilerVersion;
NOTE: Sync version is available only for lib-node binding.

Parameters

  • code: string – Contract code BOC encoded as base64 or code BOC handle

Result

  • version?: string – Compiler version, for example 'sol 0.49.0'

Types

BocCacheTypePinnedVariant

Pin the BOC with pin name.
Such BOC will not be removed from cache until it is unpinned BOCs can have several pins and each of the pins has reference counter indicating how many times the BOC was pinned with the pin. BOC is removed from cache after all references for all pins are unpinned with cache_unpin function calls.
type BocCacheTypePinnedVariant = {
pin: string
}
  • pin: string

BocCacheTypeUnpinnedVariant

BOC is placed into a common BOC pool with limited size regulated by LRU (least recently used) cache lifecycle.
BOC resides there until it is replaced with other BOCs if it is not used
type BocCacheTypeUnpinnedVariant = {
}

BocCacheType

type BocCacheType = ({
type: 'Pinned'
} & BocCacheTypePinnedVariant) | ({
type: 'Unpinned'
} & BocCacheTypeUnpinnedVariant)
Depends on value of the type field.
When type is 'Pinned'
Pin the BOC with pin name.
Such BOC will not be removed from cache until it is unpinned BOCs can have several pins and each of the pins has reference counter indicating how many times the BOC was pinned with the pin. BOC is removed from cache after all references for all pins are unpinned with cache_unpin function calls.
  • pin: string
When type is 'Unpinned'
BOC is placed into a common BOC pool with limited size regulated by LRU (least recently used) cache lifecycle.
BOC resides there until it is replaced with other BOCs if it is not used
Variant constructors:
function bocCacheTypePinned(pin: string): BocCacheType;
function bocCacheTypeUnpinned(): BocCacheType;

BuilderOpIntegerVariant

Append integer to cell data.
type BuilderOpIntegerVariant = {
size: number,
value: any
}
  • size: number – Bit size of the value.
  • value: any – Value: - Number containing integer number. e.g. 123, -123. - Decimal string. e.g. "123", "-123". - 0x prefixed hexadecimal string. e.g 0x123, 0X123, -0x123.

BuilderOpBitStringVariant

Append bit string to cell data.
type BuilderOpBitStringVariant = {
value: string
}
  • value: string – Bit string content using bitstring notation. See TON VM specification 1.0. Contains hexadecimal string representation: - Can end with _ tag. - Can be prefixed with x or X. - Can be prefixed with x{ or X{ and ended with }. Contains binary string represented as a sequence of 0 and 1 prefixed with n or N. Examples: 1AB, x1ab, X1AB, x{1abc}, X{1ABC} 2D9_, x2D9_, X2D9_, x{2D9_}, X{2D9_} n00101101100, N00101101100

BuilderOpCellVariant