Skip to main content

Entrypoints

The entrypoints of a contract represent the different ways that it can be called, similar to a method or function in many programming languages or an endpoint of an API. The entrypoints in a Tezos smart contract must meet these specifications:

  • Contracts must have at least one entrypoint.
  • Each entrypoint must have a name.
  • Entrypoints may accept parameters, which can be of almost any data type that Tezos supports.

Unlike functions and API endpoints, entrypoints do not return a value. To return a value from a smart contract, see Views.

For examples of contracts, see Examples of contracts on opentezos.com.

Entrypoint logic

An entrypoint may run all kinds of logic based on:

  • Its storage
  • The parameters that senders pass
  • Global values such as the address of the caller
  • The table of constants

Entrypoints may not access information outside Tezos, such as calling external APIs. If an entrypoint needs information from outside Tezos it must use oracles; see Using and trusting Oracles on opentezos.com.

The only effects that an entrypoint can have are changes to its storage and new transactions that are run after the entrypoint completes. For example, an entrypoint can call other entrypoints in its contract or entrypoints in other contracts.

Example entrypoints

Here is a very basic example of contract with two entrypoints:

EntrypointDescription
addadd takes an int as a parameter and adds it to the previous value of the storage
resetreset takes no parameter and replaces the storage with 0

Entrypoint implementation

Internally, entrypoints are implemented using a variant data type. The contract contains a single piece of logic that branches based on the value of that variant. In Michelson, the different values of the variant are annotated with the name of the corresponding entrypoint.

When calling a smart contract, senders provide either the full parameter as a variant or specify the name of the entrypoint and the corresponding parameter value.

Other languages have different ways of indicating entrypoints. For information about coding entrypoints in specific languages, see these links: