fundamental's of vyper
Tags: blockchain, smartcontract
Published: 2023-04-20 09:06:39

well we all have once been at that point when suddenly in midnight that one bug made it into our dream and now both our day and night have some bug to resolve.

![the almighty bug](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rptjvdix3veek4ookh4.gif)
so why does it matter in this context, well as **_java-script_** rule the world of web development as **_solidity_** rule the underworld of etherium called smart contract, but as someone said, **_best code is the code that was never written_**.
solidity have much more freedom in world of smart contract and freedom always comes with some cost some of such cost includes function overloading.
so to address some of _**solidity limitation**_ and to control some of that rich kid habit vyper was developed with python syntax as inspiration and suddenly all vyper developer became that Aladdin...

![a whole new world](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6gs9on6q20lg0ljtn9g.gif)
so in this blog we will be exploring some of basic syntax and rule for vyper.

> **pragma versioning** 

like solidity vyper also support pragma versioning, that extra line which help compiler to identify how to compile code with correct version.
```python
@version ^0.2.0
```

> **variable declaration**

due to security reason vyper is also **_statically typed language_** which means you need to specify type of your variable before compilation as compiler need them to create byte-code and that means there is no entry for masked freeloader variable.
```python
var_bool: public(bool)
senderAddress: public(address)
```
public is type declaration _{will explore them in another blog}_ means **_any user on blockchain can read this variable_**.
![freeloader](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxsfmbo5z6w9sizn8flb.gif)

> **functions**

based on visibility _(**@external**{executed by transcation from other contract}, **@internal**{executed by other internal function called self object})_ function can be executed internally or externally.

```python
def two_sum(value1: uint128, value2: uint128) -> String[60]:
    return concat("sum is: ", value1 + value2)  
```

>**events**

events are **special type of data structure that hold related data** onto blockchain transaction logs and when triggered by user will show data in given format. these usually get **triggered when some important state of chain is changed**.

```python
event fee:
    name: String[35]
    amount: uint128()
    address: address
```

>**interfaces**

communication between external function between different smart contract takes place using interfaces. so basically an interface is like a **place to gather up all external function from smart contract** to enable interaction outside world. some of conventional syntax from python classes can be used here like accessing variable, importing classes.

```python
interface ExtractAmount:
    def getBalance() -> uint256 pure
    def transferAmount() -> String[100] payable
    def requestAmount() -> bool nonpayable
    def getAddress() -> address view   
```

>**struct**

struct is basically a **fancy word to group out several variable together in contract**. these are basically used to group together related data into single object

```python
Struct Receipt:
    from: address
    to: address
    amount: uint128
    balance: uint256
```