2019-06-11 05:37:12 +04:00
---
id: entrypoints
title: Entrypoints
---
2019-11-08 03:19:27 +04:00
Entrypoints are the gates to a smart contract. In LIGO each entrypoint is a function that accepts two arguments. The first is the parameter used to invoke the contract, and the second is the current storage of the contract. Each entrypoint must return a list of operations to apply as a result of the smart contract call, and a new storage value.
2019-06-11 05:37:12 +04:00
> If you don't want to update the storage, don't worry, just re-cycle your last storage value.
## Defining an entry point
2019-11-08 03:19:27 +04:00
The contract below is effectively an empty contract. It takes a `unit` as a parameter, and returns a `unit` .
2019-06-11 05:37:12 +04:00
<!-- DOCUSAURUS_CODE_TABS -->
<!-- Pascaligo -->
2019-09-30 21:23:30 +04:00
```pascaligo
2019-06-11 05:37:12 +04:00
function main (const p : unit ; const s : unit) : (list(operation) * unit) is
block {skip} with ((nil : list(operation)), s)
```
<!-- END_DOCUSAURUS_CODE_TABS -->
## Multiple entry points
2019-11-08 03:19:27 +04:00
Multiple entrypoints are currently not supported in Michelson. But with Ligo you can work around that by using variants & pattern matching.
2019-06-11 05:37:12 +04:00
In the example below we have a simple counter contract, that can be either `Increment(int)` -ed, or `Decrement(int)` -ed.
<!-- DOCUSAURUS_CODE_TABS -->
<!-- Pascaligo -->
2019-09-30 21:23:30 +04:00
```pascaligo
2019-06-11 05:37:12 +04:00
// variant defining pseudo multi-entrypoint actions
type action is
| Increment of int
| Decrement of int
// real entrypoint that re-routes the flow based on the action (parameter) provided
function main (const action: action ; const counter: int) : (list(operation) * int) is
block {skip} with ((nil : list(operation)),
case action of
2019-06-24 19:31:55 +04:00
| Increment(number) -> counter + number
| Decrement(number) -> counter - number
2019-06-11 05:37:12 +04:00
end)
```
<!-- END_DOCUSAURUS_CODE_TABS -->