Comments

In Solidity, comments can be used to explain your code. Because your contract will be public, commenting it is the best way for people to quickly understand and trust you. Attempting to launch a spaceship without a plan would turn into a disaster, wouldn't it? Comments are also a simple way to test codes and debug it.

Single line

A single line comment starts with //. Any text on the same line will be ignored by the compiler.

pragma solidity ^0.4.24;

// Your Spaceship Factory will be written down here

Exercise
Correct!
False!

Loading...

Turn the following code into a readable Solidity source file.
// pragma solidity ^0.4.24; //start of the file

Multi lines

Multi lines comments start with /* and end with */. Any text between the two won't be executed.

pragma solidity ^0.4.24;

/*
Your Spacecrypt Factory will be written down here
Just down here
Impressive, isn't it?
*/

Exercise
Correct!
False!

Loading...

Turn the following code into a readable Solidity source file.
/* pragma solidity ^0.4.24; //start of the file */

Natspec

It is particularily useful to specify what your code should do. Solidity has chosen to use Natural Specification Format, known as natspec.

Remark: Natspec is not officially supported by Solidity. It is a de facto standard in Ethereum

Here is an example of what it looks like.

pragma solidity ^0.4.24;

/**
 * @title Contract that manages the Spaceship Factory
 * @author Buzz Lightyear
 * @notice This contract is a game. Do not use it for your real space travels.
 * @dev The contract is not implemented yet
 */
contract SpaceshipFactory {

}

The tags are denoted with an @. You will learn to master them all through the next exercises. A list of the one used above follows.

Tag
@title Title describing the contract
@author Author of the code
@notice Explanation of the code aimed at users
@dev Explanations of the code aimed at developers
Amiral tip

Notice the wordings: contract is not code. It will matter later on