Ethereum Solidity Comments


Similar to JavaScript, Solidity supports single line comments (//) and multi-line comments (/*…*/) as shown below

// This is a single-line comment.

/*
This is a
multi-line comment.
*/

Solidity contracts can also have a special form of comments for documentation. This documentation type of comments is called Ethereum Natural Specification Format (Natspec). Natspec format uses doxygen tags. It can have either one or multiple lines starting with /// or a multiline comment starting with /** and ending with */. Here is how we are using Natspec documentation in our service contract.

/// @title contract between client and contractor.
contract Service {
    address contractor; // address of the hired contractor

    /// @notice Hiring the contractor to perform the work
    /// @param _contractor Ethereum address of the contractor
    function hire (address _contractor) onlyClient {
        contractor = _contractor;
    }

    /// @notice Get the contractor assigned to the service
    /// @return contractor address
    function getContractorAddress() public constant returns (address) {
        return contractor;
    }
}

In the above code we documented the title of the contract. We also documented the two functions along with their parameters. This documentation comments are parsed by Natspec client and create documentation json files.

No comments:

Post a Comment

Ethereum Solidity Compiler

Ethereum contracts are written in the high level language called Solidity and compiled into bytecode using the Solidity compiler. This ...