Skip to content
On this page

Working with cells

Cells are the basic storage elements in the blockchain, used to represent and manipulate data in contracts. In this guide, we will explore the basic methods for working with cells provided by everscale-inpage-provider.


Note that it is also possible to work with accounts, but we will cover that in the next section.

Here is the ABI definition we'll use in our examples:

const ABI = [
  { name: 'name', type: 'string' },
  { name: 'age', type: 'uint32' },
  { name: 'city', type: 'string' },
] as const;

Cell Data Packing

To pack data into a TVM cell, use the packIntoCell method. It creates a base64 encoded BOC (Bag of Cells) from the provided data, structure, and ABI version.

import { ProviderRpcClient } from 'everscale-inpage-provider';

const provider = new ProviderRpcClient();

// Make sure the provider is initialized.
await provider.ensureInitialized();

// Request permissions from the user to execute API
// methods using the provider.
await provider.requestPermissions({ permissions: ['basic'] });

// Define the data to pack.
const dataToPack = {
  name: 'Alice',
  age: 30,
  city: 'New York',

// Pack the data into BOC.
const { boc, hash } = await provider.packIntoCell({
  structure: ABI,
  data: dataToPack,

console.log('Packed data:', boc);
console.log('Packed data hash:', hash);

Cell Data Unpacking

To unpack data from a TVM cell, use the unpackFromCell method. It decodes the base64-encoded string into an object according to the provided ABI.

// Define the data to unpack.
const bocToUnpack =

// Unpack the data from BOC.
const unpacked = await provider.unpackFromCell({
  structure: ABI,
  boc: bocToUnpack,
  allowPartial: true,
console.log('Unpacked data:',;

BOC Hash Computation

Before diving into the specifics of how to compute the hash of a base64 encoded BOC (Bag of Cells) using the getBocHash method provided by the everscale-inpage-provider.

At the most fundamental level, everything in Blockchain is a cell. Each cell consists of up to 1023 data bits and up to 4 references to other cells. Cells are organized in a tree-like structure, with each cell potentially referencing up to four other cells. The hash of a cell is a kind of complex hash derived from the cell's representation in a specific format.

It's crucial to note that this is not simply a SHA-256 hash of the byte contents of the base64 string. Instead, it involves the structured data within the cell, its references, and specific aspects of its representation.

Get BOC Hash

The getBocHash method computes the hash of a base64 encoded BOC and returns the hash as a hexadecimal string. This method requires basic permissions.

Here's an example of how to use the getBocHash method:

// Define the base64 encoded BOC.
const boc = 'te6ccgEBAwEAGQACCAAAAB4CAQAQTmV3IFlvcmsACkFsaWNl';

// Compute the hash of the base64 encoded BOC.
const hash = await provider.getBocHash(boc);

console.log('BOC hash:', hash);


In this case, getBocHash takes the base64 representation of the cell (or BOC) and computes the hash using the specific hashing method suitable for this data structure.

Public Key Extraction

The extractPublicKey method is useful when you need to obtain the public key associated with a contract's raw account state. This can be helpful, for example, when verifying the integrity of a transaction or checking the owner of a contract. Keep in mind that this method can only be used on contracts that have been deployed and have a pubkey header.

// Extract public key from boc
const publicKey = await provider.extractPublicKey(exampleBOC);

console.log('Public key:', publicKey);