Solidity File Structure

Solidity source file structure is little bit different from other programming languages. Every source file should start with a comment indicating its license. You can define the License by declaring // SPDX-License-Identifier: MIT

In the below contract our license type is MIT but you can define any license type that is suitable according to your requirement. if your code is not open source you can declare that by using the word UNLICENSED.

Trust in smart contract can be better established if their source code is available. Since making source code available always touches on legal problems with regards to copyright, the Solidity compiler encourages the use of machine-readable SPDX license identifiers.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
contract CodiesAlert {
}

Pragmas

The pragma keyword is used to enable certain compiler features or checks. A pragma directive is always local to a source file, If you import another file, the pragma from that file does not automatically apply to the importing file. 

Version Pragma

pragma solidity ^0.8.3;

A source file with the line above does not compile with a compiler earlier than version 0.8.3, and it also does not work on a compiler starting from version 0.9.0 (this second condition is added by using ^)

You can also define the compiler version range with the below statement.

You can also define the compiler version range with the below statement.

pragma solidity >0.5.0 >= 0.8.0;
 
Because there will be no breaking changes until version 0.9.0, you can be sure that your code compiles the way you intended.
 
Contract

Contracts in Solidity are similar to classes in object-oriented languages. You declare a contract by using the keyword contract followed by the contract Name. Inside the contract, you code your smart contract logic.

 

Leave a Reply

https://www.linkedin.com/company/77619036/admin/

welcome.

We connect you to a world of houseplants and urban gardening tailored to your home

Bloomer

Login to your account