Skip to main content
When you create a counter contract using npm create ton@latest, it generates the following file:
counter.tolk
Let’s explore what’s happening here.

Smart contract data

First, we declare the storage structure. It corresponds exactly to the format used when deploying from the TypeScript client wrappers/Counter.ts.

Handling incoming messages

When a client sends a message — for example, using the sendIncrease function in wrappers/Counter.ts— the contract processes it using this function:
Take a look at the sendIncrease function in TypeScript, which constructs a message containing OP_INCREASE, queryId, and increaseBy. The corresponding struct in counter.tolk defines the format of this incoming message:

Sending messages

This contract doesn’t send any messages. To learn how message construction works in Tolk, see the Create message article.

Handling internal bounced messages

Bounced messages are messages that you send, but the receiver fails to process — so they are returned to you.
Since this contract only accepts messages like IncreaseCounter and ResetCounter and doesn’t send any, you can leave this function empty or remove it entirely.

GET methods

GET methods, also called contract getters, run off-chain and typically return data from the storage.
The getCounter function in wrappers/Counter.ts calls this exact getter from counter.tolk.