How Your Contract Works

How Your Contract Works

Now that you've deployed your contract, you might be wondering how it works. Let's take a closer look at the code you wrote.

License Identifier

The first line of most Solidity files is the license identifier. This line is used to specify the license under which the code is released. In this case, the code written is released under the MIT license(opens in a new tab).

// SPDX-License-Identifier: MIT

Pragma Directive

The next line is a pragma directive(opens in a new tab). This line tells the Solidity compiler which version of the Solidity language to use. In this case, the code is written for Solidity version 0.8.0 or higher.

pragma solidity ^0.8.0;

Contract Definition

The next line defines a contract called Storage. A contract is a collection of code and data that is stored at a specific address on the blockchain. You can think of a contract as a class in an object-oriented programming language. The contract definition is followed by a pair of curly braces that contain the contract's code.

contract Storage {

Message Variable

The first thing you'll notice inside the contract definition is a variable called number. This variable is declared as a uint256, which is a Solidity type that represents a unsigned integer of characters.

    uint256 number;

Message Update Function

The next thing you'll notice is a function called store. This function takes a single argument called num of type uint256. The public keyword means that this function can be called from outside the contract by anyone. Since this function doesn't have any access control, anyone can update the message variable.

    function store(uint256 num) public {
        number = num;
    }

Last updated