Basechain
  • About Basechain
  • Base BigBang Language
    • Introduction
    • 1. Getting started
      • 1.1 Installing BigBangNet
      • 1.2 BigBang basics
    • 2. Type
      • 2.1 Primitives
      • 2.2 Sequences
      • 2.3 Composites
    • 3. Keywords
    • 4. Storing data
      • 4.1 Constants
      • 4.2 Variables
      • 4.3 Maps
    • 5. Functions
      • 5.1 Public functions
      • 5.2 Private functions
      • 5.3 Read-only functions
  • 6. Control flow & error handling
    • 6.1 Asserts
    • 6.2 Try
    • 6.3 Unwrap flavours
    • 6.4 Response checking
  • 7. Using BigBangNet
    • 7.1 Creating a new project
    • 7.2 Writing your first contract
    • 7.3 Interacting with your contract
    • 7.4 Testing your contract
  • 8. Practice projects
    • 8.1 Time-locked wallet
    • 8.2 Smart claimant
    • 8.3 Multi-signature vault
  • 9. Traits
    • 9.1 Defining traits
    • 9.2 Implement traits
    • 9.3 Passing traits as arguments
  • 10. Building a marketplace
    • 10.1 Setup
    • 10.2 Listing & cancelling
    • 10.3 Fulfilling listings
    • 10.4 Uni tests
  • 11. Runtime cost analysis
  • Nodes & Miners
    • Run a Node with Docker
    • Run a Node with DigitalOcean
    • Run a Node with a Hosted Provider
    • Base Node Configuration
    • Mine testnet Base tokens
    • Verify Miner
    • Miner costs and fees
  • Website
  • X(Twitter)
  • Github
Powered by GitBook
On this page
  1. Base BigBang Language
  2. 5. Functions

5.1 Public functions

Public functions can be called by both standard and contract principals. At least one public function is required for contracts with interactivity. However, being callable does not necessarily mean that the underlying functionality is public. Developers can include assertions to ensure that only specific contract callers or inputs are valid.

Public functions should return a response value. If the function returns an 'ok' type, the function call is considered valid, and any changes made to the blockchain state will be materialized. This means that state changes, such as updating variables or transferring tokens, will only be committed to the chain if the contract call that triggered these changes returns an 'ok'.

The effects of returning an 'ok' or an 'err' are illustrated in the example below. The function takes an unsigned integer as input and returns 'ok' if it is even or 'err' if it is odd. At the start of the function, the variable 'even-values' is incremented. To determine if the number is even, we calculate the remainder of the division by two and check if it is equal to zero using the 'is-eq' function (n mod 2 should equal 0).

Previous5. FunctionsNext5.2 Private functions

Last updated 1 year ago