Coco’s basic types are:
- Bool
- String
- Bytes
- Address
- U64 and U256
- I64 and I256
All coco variables when declared with a particular type is initialized with the zero value of that data type. This helps ensure a predictable and reliable state for all variables.
F-strings
Coco allows you to include expressions in the string literals with minimal syntax. The expressions can be declared inside the ‘{}’ brackets.
throw f"{self.name} will be {self.age + 1} years old next year"
In this throw statement the self is used to refer to the input parameters of the function.
coco Types
endpoint invokable Test1() -> (opbool Bool, opstring String, opbytes Bytes, opaddr Address, opu64 U64, opi64 I64, opu256 U256, opi256 I256):
opbool = true
opstring = "Hello"
opbytes = 0x
opaddr = Address(0)
opu64 = 10
opi64 = -10
opu256 = 100
opi256 = -100
endpoint invokable Test2(name String, age U64) -> (output U64):
throw "{self.name} is {self.age} years old"
endpoint invokable Test3() -> (opbool Bool, opstring String, opbytes Bytes, opaddr Address, opu64 U64, opi64 I64, opu256 U256, opi256 I256):
memory zbool Bool
memory zstring String
memory zbytes Bytes
memory zaddr Address
memory zu64 U64
memory zi64 I64
memory zu256 U256
memory zi256 I256
return (opbool: zbool, opstring: zstring, opbytes: zbytes, opaddr:zaddr, opu64:zu64, opi64:zi64, opu256:zu256, opi256:zi256}