---
# System prepended metadata

title: Lesson 03 - Smart Contracts with the Scilla Language Part 2

---

# Lesson 03 - Smart Contracts with the Scilla Language Part 2
Mainly Data Types

## Review (Q&A)
1. What’s the difference between the accepted and success keys in the receipt object? 
> Accepted: When "accept" function was called.
> Success: When money is successfully transferred from one account to the other.
2. Why is the network limited to ~2800 transactions per second? 
> 2400 nodes / 600 nodes/shard = 4 shards.
To increase the number of nodes / shards, need more experiments to ensure security. Given the current number of transactions, there's no urgent need to increase the number of nodes.

## Quiz
1. The Scilla programming language is Turing-complete: False. It's not Turing-complete by design (less powerful than other languages in the blockchain world) -> prevents infinite-looping applications
2. Which of these values are not an implicit variable in a contract (including transitions)? 
a. _this  :heavy_check_mark: (In Scilla there's no such thing as _this)
b. _address 
c. _balance 
d. _amount
3. Which statement is false?
a. Transitions are invoked by messages. 
b. Transitions have implicit parameters _sender and _amount
c. Procedures do not return a value to the caller.
d. Transition arguments are optional :heavy_check_mark: (Transition arguments are mandatory)
4. Which operator fetches the value of a contract field and stores it in a local variable? 
<- Reading from mutable :heavy_check_mark:
<-& Reading from immutable (must dereference)
:= to store states on the blockchain (changing / mutating contract states) (write to contract)
= is for expressions (for defining things)
<= is to assign one variable from memory to another variable in memory (write to local)
5. Which of the following is not a form of communication in Scilla?
a. ErrorMessages :heavy_check_mark: (doesn't exist in Scilla) 
b. messages
c. events
d. exceptions

## 3.1 Working with integers and strings

### Integers
* can be signed / unsigned with sizes of 32, 64, 128, 256 bits

* Implicit variables _amount and  _balance are Uint128 (recap: passed to every transition calls)

* Buffer underflow/overflow (overflow: return zero after max positive number. this is not allowed), division by zero errors. These 2 will return runtime exceptions. (recap: we can throw error but cannot handle error)

![Integer Syntax](https://i.imgur.com/iyAHQAE.png)

### Strings

* No hard limit on length, but likely enforced by network (i.e. just that the requests will timeout)

* Support operations such as eq, concat, substr, strlen, etc.

* Only the substr fails with an error, with invalid params.

![String Syntax](https://i.imgur.com/YGvX6vq.png)

## 3.2 Byte strings, addresses and block numbers

### Byte Strings
* A ByStr32 represents a 32-byte hash (64hex chars)
* A ByStr32 literal is prefixed with 0x
* sha256hash, keccak256hash, ripemd160hash (20 bytes)

### Addresses
* Correspond to wallets and contracts 
* Addresses are of type ByStr20 (40 hex chars)
* Often used in identity or ownership concerns

![Byte Strings and Addresses Syntax](https://i.imgur.com/l2IeU5d.png)

### Block Numbers
* Uses dedicated type BNum
* Represents identifiers of blocks being mined (unique to each block) 
* Often used as stand-in for time values (goes back to the fact that blockchain implementation has to be deterministic, cannot be based on actual time, since value becomes different over time)

![Block Numbers Syntax](https://i.imgur.com/DUocHXh.png)


### Assignment 3A

## 3.3 Working with maps

* Maps are key value stores, and can be nested
* keys can be of types: String, IntX, UintX, ByStrX
* Values can be of any type except functions
* Emp: empty map

![Maps Syntax](https://i.imgur.com/EeBQ6Xs.png)

## 3.4 Booleans and options
> monad, monoid
* Boolean is an Algebraic Data Type (ADT), specified as Bool.
* ADTs are composite type in functional programming.
* Has two constructors, True and False, which take no args. (Constructors here are not exactly the same as how constructors are usually defined in other languages)
* | is called monads / predicates. can only be 2 of this in each match (in the case of booleans)

### Options
* Optional values are specified using the type Option t
* The Some constructor represents the presence of value
* The None constructor represents the non-existence of value

## 3.5 Lists and pairs

* Defined as List t, and it has 2 constructors: Nil & Cons
* Nil represents an empty list and takes no arguments
* Cons constructs a list, from a value and an existing list
* Cons adds elements to the front of the list (one element at a time)
* All elements in a list must be of type t
* Traversal via list_foldl, list_foldr, list_foldk
* `in` is to terminate expressions in the library

### Pairs

* Specified as Pair t1 t2, represents a pair of values
* Only has one constructor, Pair, takes 2 args of types t1, t2
* t1 and t2 need not be of the same type
* fst: polymotic function (need to pass the different types that return a function that return those different types, similar to currying) 
## 3.6 Standard libraries


| Utils     | Keywords                                                                            |
| --------- | ----------------------------------------------------------------------------------- |
| BoolUtils | andb, orb, negb, bool_to_string                                                     |
| IntUtils  | intX_eq, uintX_eq, intX_lt, uintX_lt, intX_neq, uintX_neq, intX_le, uintX_le, etc   |
| ListUtils | list_map, list_filter, list_length, list_eq, list_exists, list_sort, list_find, etc |
| NatUtils  | nat_prev, nat_eq, nat_to_int, etc                                                   |
| PairUtils | fst,snd                                                                             |