Back

Lesson 3:
Constants

Introduction to Vyper constants

Progress: 0%

Visit desktop version for better experiences.

Constants

Constants are variables that is only defined at a global level. Use the keyword constant to define a constant variable.

# pragma version 0.4.0 SUPPLY_AMOUNT: constant(uint256) = 21000000 BYTES_VALUE: constant(bytes32) = 0xabcd1123f8ae9a65dcc16f95643f2030aa505c6b465c8206e26ae84b525cdacb STRING_VALUE: constant(String[13]) = "Hello, world!" @external def retrieveConstants() -> (uint256, bytes32, String[13]): return (SUPPLY_AMOUNT, BYTES_VALUE, STRING_VALUE)
Vyper Differentiators
  • Requires explicit specification of String length.
  • String length in return function must be equal to more than the constant length.

Further Reading:

© 2025 Scroll Foundation | All rights reserved

Terms of UsePrivacy Policy