Skip to content

Latest commit

 

History

History
55 lines (31 loc) · 1.65 KB

state_vars_and_ints.md

File metadata and controls

55 lines (31 loc) · 1.65 KB

Chapter 2: State Variables, Integers & Constants

Great job! Now that we've got a shell for our contract, let's learn about how Vyper deals with variables.

State variables are permanently stored in contract storage. This means they're written to the Ethereum blockchain. Think of them like writing to a DB.

Example

# @version >=0.2.4 <0.3.0

# This will be stored permanently in the blockchain
storedData: int128

In this example contract, we created a int128 called storedData which holds a default value of 1.

Unsigned Integers: uint256

The uint256 data type is an unsigned integer (256 bit), meaning its value must be non-negative.

There's also an int128 (128 bit) data type for signed integers (a type to store positive and negative integers).

Example

# @version >=0.2.4 <0.3.0

# This creates a constant uint256 with a value of 10
TEN: constant(uint256) = 10

In this example contract, we created a constant uint256 called TEN and set it equal to 10.

Put it to the test

Our Pokemon DNA is going to be determined by a 16-digit number.

In the coding area on right-side, declare a constant uint256 named DNA_DIGITS, and set it equal to 16.

** Template **

embedded-code

** Solution **

embedded-code-final

** Previous Chapter Solution **

embedded-code-previous