Skip to main content
Get methods are smart contract methods that are supposed to be executed off-chain. They are useful for structured retrieval of data from a smart contract (get_collection_data get-method on an NFT collection), and for any logic that is a part of a smart contract but is needed off-chain (get_nft_address_by_index get-method on an NFT collection). Under the hood of APIs, this happens by fetching the actual state of the smart contract from the blockchain and executing TVM to get the result. This process is purely read-only and does not modify the blockchain state in any way.

Defining

Get methods are processed by the function selector. By convention, the ID of a get method is calculated as crc16("name") | 0x10000 where name is set by the developer. This simplifies practical usage because a human-readable name has to be used instead of some arbitrary number. A minimal example of a smart contract that has a get method that follows the ID convention:
But in practice, it is easier to use PROGRAM{ from the Fift assembler that handles function selector logic.
The above is equivalent to the following Tolk code, which compiles to almost identical Fift code.
Tolk

Executing

In order to execute a get method, the actual state of the smart contract has to be fetched, and TVM has to be executed with c7 initialized and the desired parameters pushed on the stack.

Local way

With all the required values known, it is possible to execute a get method completely locally. A minimal example that uses a placeholder c7 for simplicity, as it is only necessary when the get method uses data from it during execution:
Note that if the get method uses some values from c7, for example with instructions such as NOW or MYCODE, the c7 tuple should be populated according to its structure.

Decentralized way

The process of fetching the actual contract state and initializing c7 can be handled by liteserver for easier execution. To execute a get method via liteserver, the request follows the liteServer.runSmcMethod TL schema. In that request, params:bytes is a BoC of a serialized VmStack object containing the stack with arguments. The response follows the liteServer.runMethodResult TL schema. Apart from the values used for initialization and proofs, the result is included as result:mode.2?bytes, which is a BoC of a serialized VmStack object, similarly to the request. An example execution via liteclient that handles serialization:
Result:

High-level API

The easiest path is using a high-level API, such as TON Center. It has a /api/v3/runGetMethod endpoint that takes a smart contract address, a get method name, and arguments and returns the resulting stack. Example usage:
The result for this call is presented below. The stack in this case contains a single cell element in BoC format.