Blockchain 5 min read

How to Eliminate Common Solidity Compilation Warnings in Remix

This guide explains why Remix shows two typical Solidity compiler warnings—missing visibility and missing pure mutability—and demonstrates step‑by‑step code modifications that remove both warnings while clarifying function visibility and state‑mutability modifiers.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
How to Eliminate Common Solidity Compilation Warnings in Remix

Introduction

Many online Solidity tutorials ignore compiler warnings; this article uses two simple examples to show how to clear those warnings when compiling with Remix.

Example Contract

The original contract is:

pragma solidity ^0.4.0;
contract HelloWarning {
    function hello() returns (string) {
        return "Hello Warning!";
    }
}

Compiling it in Remix produces two warnings:

browser/HelloWarning.sol:5:5: Warning: No visibility specified. Defaulting to "public".
browser/HelloWarning.sol:5:5: Warning: Function state mutability can be restricted to pure.

Fixing the “public” warning

Add the public visibility specifier to the function:

pragma solidity ^0.4.0;
contract HelloWarning {
    function hello() public returns (string) {
        return "Hello Warning!";
    }
}

After recompiling, the first warning disappears. Solidity defines four visibility modifiers:

public – callable from both outside and inside the contract.

internal – callable only within the contract and its derived contracts.

external – callable from other contracts and transactions.

private – callable only inside the defining contract.

Fixing the “pure” warning

Replace the missing mutability specifier with pure, which supersedes the older constant keyword:

pragma solidity ^0.4.0;
contract HelloWarning {
    function hello() public pure returns (string) {
        return "Hello Warning!";
    }
}

Recompiling now eliminates the second warning as well.

Conclusion

Addressing each compiler warning not only produces cleaner code but also deepens understanding of Solidity’s visibility and mutability modifiers, leading to safer and more maintainable smart contracts.

smart contractsSolidityRemixBlockchain DevelopmentCompilation Warnings
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.