Last active
January 27, 2020 01:02
-
-
Save psvehla/ed299733c3fa07e9818601033ab3fca1 to your computer and use it in GitHub Desktop.
A hello world Vyper contract.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.3; // Solidity version 0.5.3, pragma used to enable certain compiler features or checks | |
contract HelloWorld // defining the contract | |
{ | |
string greeting; // defining the state string variable 'greeting' | |
constructor() // constructor function, optional, executed once upon deployment and cannot be called again | |
public | |
{ | |
greeting = "Hello, World."; | |
} | |
function printGreeting() // defining a function | |
public // this function is callable by anyone | |
view // dictates that this function promises to not modify the state | |
returns (string memory) // function returns a string variable from memory | |
{ | |
return greeting; | |
} | |
function setGreeting(string memory _greeting) | |
public | |
// notice that this function contains no "view" -- it modifies the state | |
{ | |
greeting = _greeting; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
greeting: public(bytes[32]) # defining greeting state variable, just like Solidity | |
@public | |
def __init__(): # initialization function, same as Solidity's constructor function | |
self.greeting = "Hello, World." | |
@public # function can be called internally and externally | |
@constant # function will not change state | |
def printGreeting() -> bytes[32]: | |
return self.greeting | |
@public | |
def setGreeting(_greeting: bytes[32]): # a state changing function | |
self.greeting = _greeting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment