Skip to content

Socialstranger/solidity101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solidity 101

Introduction

Welcome to Solidity 101, a comprehensive guide to understanding and developing smart contracts using the Solidity programming language. This project utilizes the Hardhat framework and supports Solidity version 0.8.28.

Table of Contents

  1. Getting Started
  2. Installation
  3. Creating a Smart Contract
  4. Testing Smart Contracts
  5. Deploying Contracts
  6. Conclusion

Getting Started

This project is tailored towards developers who wish to learn about the basics of Solidity and smart contract development. Ensure you have the following installed:

  • Node.js (version 12.x or newer)
  • npm (Node package manager)

Installation

To set up the development environment, follow these steps:

  1. Clone the repository:
    git clone https://github.com/Socialstranger/solidity101.git
    cd solidity101
  2. Install the required dependencies:
    npm install
  3. Install Hardhat:
    npx hardhat

Creating a Smart Contract

  1. Create a new contract file in the contracts directory:
    pragma solidity ^0.8.28;
    
    contract MyContract {
        string public greeting;
        
        constructor(string memory _greeting) {
            greeting = _greeting;
        }
    }

Testing Smart Contracts

Testing is crucial. In the test directory, create a new test file:

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("MyContract", function () {
    it("Should return the correct greeting", async function () {
        const MyContract = await ethers.getContractFactory("MyContract");
        const myContract = await MyContract.deploy("Hello, Solidity!");
        await myContract.deployed();
        expect(await myContract.greeting()).to.equal("Hello, Solidity!");
    });
});

Deploying Contracts

To deploy your contract, create a deployment script in the scripts folder:

async function main() {
    const MyContract = await ethers.getContractFactory("MyContract");
    const myContract = await MyContract.deploy("Hello, Solidity!");
    await myContract.deployed();
    console.log(`Contract deployed to: ${myContract.address}`);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

Conclusion

This project aims to provide a basic understanding of Solidity, including smart contract creation, testing, and deployment using Hardhat. For more advanced topics, consider exploring further resources, tutorials, and the official Solidity documentation. Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors