View

Solidity

परिभाषा

View modifier functions को mark करने के लिए use होता है जो state read करते हैं लेकिन modify नहीं करते। View functions को externally call करना gas-free है। View functions state variables read कर सकते हैं, other view/pure functions call कर सकते हैं, लेकिन state change नहीं कर सकते।

English version

The view modifier is used to mark functions that read state but do not modify it. Calling view functions externally is gas-free. View functions can read state variables, call other view/pure functions, but cannot change state.

Code Example

contract Example {
    uint256 public value;

    // Fonction view : lit l'état
    function getValue() public view returns (uint256) {
        return value;
    }

    // Calcul basé sur l'état
    function getDouble() public view returns (uint256) {
        return value * 2;
    }

    // INVALIDE : modifie l'état
    // function increment() public view {
    //     value++; // ERROR
    // }
}

संबंधित शब्द

Solingo पर इस concept को practice करें

View को interactive exercises और integrated IDE के साथ master करें।

मुफ्त में शुरू करें