Skip to content
On this page

Flags โ€‹

Several aspects of scenarios and the compilation of contracts can be controlled by the use of flags.

SmartPy supports two sorts of flags:

Boolean Flags โ€‹

FlagDescriptionDefault Value
contract-check-exceptionFail in the interpreter when sp.contract(...) evaluates to none.True
view-check-exceptionFail in the interpreter when sp.view(...) evaluates to none.True
disable-dup-checkRemove the DUP protection on ticketsFalse
dump-michelDump Michel intermediate languageFalse
erase-commentsRemove compiler commentsFalse
erase-var-annotsRemove annotations (with RENAME) after SENDER, BALANCE, etcFalse
initial-castAdd an initial CAST to remove annotations first in the compilerFalse
pairnUse PAIR n instructionTrue
simplifyAllow simplification after compilationTrue
simplify-via-michelUse Michel intermediate languageFalse
single-entrypoint-annotationEmit parameter annotations for single entrypoint contractsTrue
stop-on-errorScenarios stop on first errorTrue
warn-unusedExceptions for unused entrypoint parametersTrue
decompileDecompile after compilation (for test purposes)False
default-check-no-incoming-transferDefault value for check-no-incoming-transfer parameter in entrypoints.False

Flags with arguments โ€‹

FlagDescriptionOptionsDefault Value
protocolProtocol used in the scenariojakarta, kathmandu, limalima
lazy-entrypointsUse big maps to store entrypointsnone, single, multiplenone
exceptionsControl exception generation in the compilerfull-debug, debug-message, verify-or-line, default-line, line, default-unit, unit.
See Exception Optimization Levels
default_variant_layoutSelect default layout for variantstree, combtree
default_record_layoutSelect default layout for recordstree, combtree

Adding flags to a contract โ€‹

Add a flag where flag is a string constant and args are potential arguments.

Boolean flag โ€‹

class MyContract(sp.Contract):
    def __init__(self, **kargs):
        # Enable flag
        # Or disable flag

Flag with arguments โ€‹

class MyContract(sp.Contract):
    def __init__(self, **kargs):

        self.add_flag("exceptions", "unit")

Adding flags to a scenario โ€‹

Same as in Adding flags to a contract, but instead provided in a test scenario.

@sp.add_test(name = "FlagExample")
def test():
    scenario = sp.test_scenario()
    scenario.add_flag("protocol", "edo")

Exception Optimization Levels โ€‹

Defines the default exception behavior when FAILWITH instructions get called.

See reference Exception Optimization template.

The different levels are:

full-debugThis is extremely costly in terms of size and gas. Useful for debugging purposes. Type of failure, line number, some parameters
debug-messageThis is still very costly in terms of size and gas
verify-or-line (default)Puts messages for verify and failwith. Uses line numbers for other failures.
default-linePuts messages for verify with custom messages and failwith. Uses line numbers for other failures.
lineOnly puts line numbers everywhere
default-unitPuts messages for verify with custom messages, and failwith. Uses unit for other failures.
unitAlways puts unit

Configuration Example

class MyContract(sp.Contract):
    def __init__(self, **kargs):
        # Enable flag
        self.add_flag("exceptions", "full-debug")