Skip to content

1.3. Pragma Directives#

Syntax#


PragmaDirective = (* pragma_keyword: *) PRAGMA_KEYWORD
(* pragma: *) Pragma
(* semicolon: *) SEMICOLON;

Pragma = (* variant: *) AbicoderPragma
| (* variant: *) ExperimentalPragma
| (* variant: *) VersionPragma;

AbicoderPragma = (* abicoder_keyword: *) ABICODER_KEYWORD
(* version: *) IDENTIFIER;

ExperimentalPragma = (* experimental_keyword: *) EXPERIMENTAL_KEYWORD
(* feature: *) ExperimentalFeature;

ExperimentalFeature = (* variant: *) IDENTIFIER
| (* variant: *) StringLiteral;

VersionPragma = (* solidity_keyword: *) SOLIDITY_KEYWORD
(* sets: *) VersionExpressionSets;

VersionExpressionSets = (* item: *) VersionExpressionSet ((* separator: *) BAR_BAR (* item: *) VersionExpressionSet)*;

VersionExpressionSet = (* item: *) VersionExpression+;

VersionExpression = (* variant: *) VersionRange
| (* variant: *) VersionTerm;

VersionRange = (* start: *) VersionLiteral
(* minus: *) MINUS
(* end: *) VersionLiteral;

VersionTerm = (* operator: *) VersionOperator?
(* literal: *) VersionLiteral;

VersionOperator = (* variant: *) CARET
| (* variant: *) TILDE
| (* variant: *) EQUAL
| (* variant: *) LESS_THAN
| (* variant: *) GREATER_THAN
| (* variant: *) LESS_THAN_EQUAL
| (* variant: *) GREATER_THAN_EQUAL;

VersionLiteral = (* variant: *) SimpleVersionLiteral
| (* variant: *) SINGLE_QUOTED_VERSION_LITERAL
| (* variant: *) DOUBLE_QUOTED_VERSION_LITERAL;

SimpleVersionLiteral = (* item: *) VERSION_SPECIFIER ((* separator: *) PERIOD (* item: *) VERSION_SPECIFIER)*;

VERSION_SPECIFIER = «VERSION_SPECIFIER_FRAGMENT»;

SINGLE_QUOTED_VERSION_LITERAL = "'" «VERSION_SPECIFIER_FRAGMENT» ("." «VERSION_SPECIFIER_FRAGMENT»)* "'";

DOUBLE_QUOTED_VERSION_LITERAL = '"' «VERSION_SPECIFIER_FRAGMENT» ("." «VERSION_SPECIFIER_FRAGMENT»)* '"';

«VERSION_SPECIFIER_FRAGMENT» = (("0""9") | "x" | "X" | "*")+;

(* Never reserved *)
ABICODER_KEYWORD = "abicoder";

(* Never reserved *)
EXPERIMENTAL_KEYWORD = "experimental";

(* Never reserved *)
SOLIDITY_KEYWORD = "solidity";

Version Pragma#

This line declares which Solidity language version it was written for. This is to ensure that the contract is not compilable with a new (breaking) compiler version, where it could behave differently. An error is produced if the running compiler version does not match these requirements.

Note that multiple version pragmas are supported, and the compiler will verify each pragma separately.

For example, this line specifies that the source code is written for Solidity version 0.4.16, or a newer version of the language up to, but not including version 0.9.0:

pragma solidity >=0.4.16 <0.9.0;

ABI Coder Pragma#

Used to instruct the compiler to choose a specific ABI encoder/decoder. The new ABI coder (v2) is able to encode and decode arbitrarily nested arrays and structs. It might produce less optimal code and has not received as much testing as the old encoder.

pragma abicoder v1;
// OR
pragma abicoder v2;

Experimental Pragma#

It can be used to enable features of the compiler or language that are not yet enabled by default. Compilers should produce an error on unrecognized pragmas (or earlier versions before they were released), and a warning before the stable version. After the stable version, this should not have an effect.

ABIEncoderV2#

Please see the abicoder pragma defined above.

pragma experimental ABIEncoderV2;

SMTChecker#

If you use SMTChecker, then you get additional safety warnings which are obtained by querying an SMT solver. The component does not yet support all features of the Solidity language and likely outputs many warnings. In case it reports unsupported features, the analysis may not be fully sound.

pragma experimental SMTChecker;

Note

This section is under construction. You are more than welcome to contribute suggestions to our GitHub repository.