Solidity is the main language used to write smart contracts on Ethereum. It helps create programs that run on the Ethereum blockchain to automate tasks and agreements.
0
0
Why Solidity is the language of Ethereum in Blockchain / Solidity
Introduction
When you want to create a smart contract for a decentralized application (dApp).
When you need to automate agreements like payments or ownership on Ethereum.
When building tokens or digital assets that live on the Ethereum blockchain.
When you want to create rules that run exactly as programmed without downtime.
When you want to interact with Ethereum's blockchain using code.
Syntax
Blockchain / Solidity
pragma solidity ^0.8.0;
contract ContractName {
// contract code here
}pragma solidity sets the Solidity version to use.
contract defines a smart contract, like a class in other languages.
Examples
This example shows a simple contract that stores and retrieves a number.
Blockchain / Solidity
pragma solidity ^0.8.0; contract SimpleStorage { uint storedData; function set(uint x) public { storedData = x; } function get() public view returns (uint) { return storedData; } }
This contract creates a simple token system where you can add tokens to an address and check balances.
Blockchain / Solidity
pragma solidity ^0.8.0; contract Token { string public name = "MyToken"; mapping(address => uint) balances; function mint(address to, uint amount) public { balances[to] += amount; } function balanceOf(address owner) public view returns (uint) { return balances[owner]; } }
Sample Program
This contract stores a greeting message and has a function to return it.
Blockchain / Solidity
pragma solidity ^0.8.0; contract HelloEthereum { string public greeting = "Hello, Ethereum!"; function sayHello() public view returns (string memory) { return greeting; } }
OutputSuccess
Important Notes
Solidity is designed specifically for Ethereum, so it fits well with how Ethereum works.
It looks similar to JavaScript and C++, making it easier to learn for many developers.
Smart contracts written in Solidity run exactly as programmed without downtime or censorship.
Summary
Solidity is the main language for writing smart contracts on Ethereum.
It helps automate agreements and create decentralized applications.
Its design fits Ethereum's blockchain and makes programming smart contracts easier.