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.
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...
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.
@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.
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.
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.
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.
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.
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
Struct Receipt:
from: address
to: address
amount: uint128
balance: uint256
Top comments (0)