Home » Blog » Solidity Smart Contracts for Beginners

Solidity Smart Contracts for Beginners

To get started building a Solidity contract there are only a few things all contracts should include.

  1. SPDX-License-Identifier
  2. Pragma compiler type and version
  3. Name of the contract

Docs – https://docs.soliditylang.org/en/latest/layout-of-source-files.html

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Demo {
}

What Do These Things Do?

Great question! Let’s walk through each one and get a better understanding of what it does and why it is used.

// SPDX-License-Identifier

The SPDX license identifier tells developers who may use the contract, how it can be used. There is no validation on this field, however, there is a list of acceptable license here.

pragma solidity >=0.7.0 <0.9.0

The pragma tells the compiler what the source file is written in and what versions this code can be compiled with.

In the example we are specifying Solidity as the source file language and it can be compiled using versions ranging from 0.7.0 to anything less than 0.9.0.

If we wanted to use anything from 0.7.x, to allow for compilers to use bug fix version, we would write:

pragma solidity ^0.7.0

If for some reason, we wanted to be absolutely sure we weren’t using any other version we would write:

pragma solidity 0.7.0

Contract Name

The most import piece from the sample code is:

contract Demo

This is the start of your newly created smart contract!

We will go into more details on implementing a smart contract in a following series tagged Learn Solidity but for now, just know this defines the name of your contract and how other contracts can reference it.

Leave a Reply

Your email address will not be published.