Anandi Work
Contact
  • About Anandi
  • SKILLS & EXPERIENCE
    • Frontend
      • ReactJS
      • Next.js – The React Framework for Production
      • ChartJS / D3.JS / Fabric JS
      • Three.JS: The JavaScript Library for 3D Graphics
      • HTML/CSS/JS/Tailwind CSS/Bootstrap
      • Material UI – The Ultimate React UI Framework
      • ShadCN/UI – The Modern UI Library for React
    • Backend
      • NodeJS & ExpressJS
      • Web3.JS
      • Python & Django
      • GoLang
      • TypeScript
    • Database
      • PostgreSQL
      • MongoDB - NOSQL Database
      • MySQL
    • API
      • REST API
      • GraphQL API
      • RPC (Remote Procedure Call)
      • WebSocket
    • Solidity
    • BLOCKCHAIN
      • Ethereum
      • Solana
      • Arbitrum
      • Bitcoin
      • Binance
      • Hyperledger
    • Wallet Integration
      • Reown Appkit
      • Rainbow Walletkit
      • Web3 Modal
      • WalletConnect
      • Wagmi
      • Metamask & Safewallet SDKs
    • Web3 SDKs & API Providers
      • Alchemy
      • Moralis
      • QuickNode
      • BitQuery API & Stream
      • ThirdWeb
      • Infura
      • Li.Fi
      • 1Inch API
      • Uniswap API
      • OpenZeppelin
    • On Chain Trading Platform & Telegram Bot
      • Bullx
      • Wave Bot
      • GMGN
      • Shuriken
      • Magnum Trade
      • Trojan
  • PROTOCOLS
    • ERCs & EIPs
      • ERC-20: The Standard for Fungible Tokens
      • ERC-721: The Standard for Non-Fungible Tokens (NFTs)
      • ERC 4337
      • ERC 6551: Token Bound Accounts (TBA)
      • ERC 7702
  • ARTICLES
    • Medium
Powered by GitBook
On this page
  • What is Solidity?
  • Solidity Architecture & Workflow
  • Solidity Workflow
  • Example Solidity Smart Contract
  • Why Use Solidity Over Other Languages?
  • Where Solidity is Used?

Was this helpful?

  1. SKILLS & EXPERIENCE

Solidity

What is Solidity?

Solidity is a high-level programming language specifically designed for writing smart contracts that run on Ethereum and other EVM-compatible blockchains. It is statically typed, meaning variables must have a fixed type, and it is influenced by languages like JavaScript, Python, and C++.

Solidity enables developers to build decentralized applications (dApps) such as DeFi protocols, NFTs, DAOs, and token contracts.

Solidity Architecture & Workflow

Solidity follows a well-structured Ethereum-based architecture that ensures security, transparency, and decentralization.

Architecture Diagram

Here’s how a Solidity smart contract interacts with the blockchain:

+------------------+        +------------------+        +--------------------+
|  Solidity Code   | -----> |  EVM Bytecode    | -----> |  Ethereum Virtual  |
|  (Smart Contract)|        |  (Compiled Code) |        |  Machine (EVM)     |
+------------------+        +------------------+        +--------------------+
         |                           |                        |
         v                           v                        v
+------------------+        +------------------+        +--------------------+
|  Web3.js/Ethers.js| -----> |  Ethereum Node  | -----> |  Blockchain Storage |
+------------------+        +------------------+        +--------------------+

Solidity Workflow

  1. Write a Smart Contract in Solidity.

  2. Compile the contract into EVM Bytecode using tools like Solidity Compiler (solc).

  3. Deploy the contract to the Ethereum blockchain using Web3.js, Ethers.js, or Hardhat.

  4. Interact with the contract using a front-end dApp, a wallet like MetaMask, or scripts.

Example Solidity Smart Contract

Let's write a simple "Hello World" smart contract that allows users to set and get a message.

1. Create a Solidity Smart Contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
    string private message;

    // Constructor sets the initial message
    constructor(string memory _message) {
        message = _message;
    }

    // Function to update the message
    function setMessage(string memory _newMessage) public {
        message = _newMessage;
    }

    // Function to retrieve the current message
    function getMessage() public view returns (string memory) {
        return message;
    }
}

2. Compile and Deploy the Contract

To deploy the contract, you can use Hardhat, Remix, or Truffle.

Using Remix (Easiest)

  1. Open Remix IDE.

  2. Create a new Solidity file (HelloWorld.sol).

  3. Paste the code and Compile it.

  4. Deploy using Injected Web3 (MetaMask).

Using Hardhat (More Advanced)

  1. Install Hardhat

npm install --save-dev hardhat
  1. Create Hardhat Project:

npx hardhat
  1. Compile and deploy the contract

npx hardhat compile
npx hardhat run scripts/deploy.js --network localhost

Why Use Solidity Over Other Languages?

1. Optimized for Smart Contracts

  • Solidity is purpose-built for writing Ethereum smart contracts, unlike other languages like Python or JavaScript.

2. EVM Compatibility

  • Solidity is designed to run on Ethereum Virtual Machine (EVM), making it the best choice for Ethereum-based dApps.

3. Security-Oriented

  • Solidity offers features like modifiers, access control, and reentrancy guards to prevent common vulnerabilities.

4. Large Developer Community

  • Solidity has strong community support, making it easier to find resources, audits, and libraries.

5. Interoperability

  • Solidity contracts can be integrated with Web3.js, Ethers.js, and other blockchain tools.

Where Solidity is Used?

  • DeFi (Decentralized Finance) – Uniswap, Aave, Compound

  • NFTs (Non-Fungible Tokens) – OpenSea, CryptoPunks

  • DAOs (Decentralized Autonomous Organizations) – MakerDAO, Aragon

  • Token Contracts – ERC-20, ERC-721, ERC-1155

  • Gaming & Metaverse – Axie Infinity, Decentraland

PreviousWebSocketNextBLOCKCHAIN

Last updated 2 months ago

Was this helpful?