Basics

Structuring Your Code

Let's begin with a fundamental aspect: code organization. It's advisable to structure your code into four key components:

  1. Endpoints
  2. View Functions
  3. Private Functions
  4. Storage

This approach facilitates efficient code navigation, making it easier for you to locate specific sections. Moreover, it enhances collaboration with other developers working on the smart contract. Additionally, consider segmenting endpoints based on their access levels. Some endpoints may exclusively serve the contract owner, while others may grant access to a predefined whitelist of addresses, and some may be accessible by anyone.

While the recommended order follows the sequence above, the actual order is less critical, as long as you maintain clear separation between these code segments. For even better code organization, consider encapsulating these components within separate modules.

Was this page helpful?