Config
The list of precompiled contracts is stored in the blockchain configuration:list:(HashmapE 256 PrecompiledSmc) represents a mapping of contract code hash to constant gas amount. A contract is considered precompiled if its code hash exists in this map.
View current values on mainnet at ConfigParam 45 on Tonviewer.
Accessing precompiled gas value
Contracts can check their precompiled gas value using theGETPRECOMPILEDGAS opcode:
- Returns the configured
gas_usagevalue if the contract code hash is inConfigParam 45 - Returns
nullif the contract code hash is not inConfigParam 45
c7 register environment tuple.
Execution modes
When a validator processes a transaction, the execution mode depends on whether the contract code hash is listed inConfigParam 45.
1. Contract is not precompiled
The contract code hash is not inConfigParam 45. TVM executes normally with standard gas accounting.
GETPRECOMPILEDGAS returns null. Transaction result: gas_used reflects actual TVM consumption.
2. Contract is precompiled
The contract code hash exists inConfigParam 45. The validator checks the contract balance against the configured gas_usage. If insufficient, the compute phase fails with cskip_no_gas.
Otherwise, execution proceeds via one of two paths.
Contract has native C++ implementation
The native C++ implementation is available and enabled in the validator node. The validator executes the C++ code directly without invoking TVM. Transaction result:gas_usedset to the value fromConfigParam 45vm_steps,vm_init_state_hash,vm_final_state_hashset to zero
Contract has no native C++ implementation
The native C++ implementation is disabled or unavailable in the validator node. TVM executes the contract code normally.GETPRECOMPILEDGAS returns the configured gas value during execution.
After execution completes, the validator overrides the compute phase values.
Transaction result:
gas_usedset to the value fromConfigParam 45vm_steps,vm_init_state_hash,vm_final_state_hashset to zero
The override ensures that both execution paths produce identical transaction results. This allows validators with and without native C++ implementations to coexist in the network and enables gradual adoption when adding new entries to
ConfigParam 45.Example: Stablecoin jetton wallet
The jetton wallet from the stablecoin-contract project is the first contract code hash added toConfigParam 45 on mainnet. This jetton wallet is optimized as a precompiled contract to reduce computation fees for stablecoin transfers.
The contract implements standard jetton wallet functionality with additional governance features. The precompiled gas logic is implemented in gas.fc.