5.2 Private functions

Private functions are defined in the same way as public functions, but they can only be called by the current contract and not from other smart contracts or by sending a transaction directly. They are useful for creating utility or helper functions to reduce code repetition. Consider creating a separate private function if you find yourself repeating similar expressions in multiple locations.

The contract below restricts updates to the recipients' map to the contract owner through two public functions. The tx-sender check is abstracted away to its private function called is-valid-caller, eliminating the need for repetition.

Last updated