1. Home
  2. /
  3. Solidity
  4. /
  5. Counter Contract

Counter Contract - Solidity Typing CST Test

Loading…

Counter Contract — Solidity Code

Demonstrates a simple counter smart contract with theme toggle functionality simulated as a boolean.

pragma solidity ^0.8.0;

contract Counter {
	uint public count = 0;
	bool public isDark = false;

	function increment() public {
		count++;
	}

	function decrement() public {
		count--;
	}

	function reset() public {
		count = 0;
	}

	function toggleTheme() public {
		isDark = !isDark;
	}

	function getUI() public view returns (uint, bool) {
		return (count, isDark);
	}
}

Solidity Language Guide

Solidity is a statically typed, contract-oriented programming language designed for building smart contracts on the Ethereum blockchain. It enables developers to write decentralized applications (dApps), manage digital assets, and automate trustless logic using a syntax inspired by JavaScript, C++, and Python.

Primary Use Cases

  • ▸Smart contract development
  • ▸DeFi protocols (DEXs, lending, staking)
  • ▸NFT standards (ERC-721, ERC-1155)
  • ▸Token creation (ERC-20)
  • ▸DAO governance mechanisms
  • ▸Permissioned enterprise blockchain apps

Notable Features

  • ▸Contract-oriented design
  • ▸Strong static typing
  • ▸Events for EVM logs
  • ▸Function modifiers
  • ▸Library & inheritance support

Origin & Creator

Solidity was created by Gavin Wood and the Ethereum Foundation in 2014 to serve as the primary language for writing smart contracts on the Ethereum blockchain.

Industrial Note

Solidity is heavily used in decentralized finance (DeFi), NFT marketplaces, blockchain gaming, DAOs, tokenization engines, supply chain tracking, on-chain governance, and enterprise blockchain automation.

More Solidity Typing Exercises

Solidity Simple AdditionSolidity FactorialSolidity Fibonacci SequenceSolidity Max of Two NumbersSolidity Array SumSolidity Even Numbers FilterSolidity String ConcatenationSolidity Counter With Loop SimulationSolidity Conditional Increment

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher