Skip to content

Latest commit

 

History

History
77 lines (49 loc) · 2.87 KB

README.md

File metadata and controls

77 lines (49 loc) · 2.87 KB

Sample Solidity Project

This is a sample solidity project, aims to help one to get started into the world of smart contracts. For step to step guide refer Setting up solidity and writing our first smart contract.

Pre Requisites

Before running any command, ensure npm and node are installed. To check if Node.js and NPM is already installed, input the following commands in the terminal:

node --version
npm --version

Go to Node.js if you need to install it.

Setup

The project include following dev dependenies.

Sample-Counter-Contract

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

import "hardhat/console.sol";

contract Counter {
    uint256 count; // persistent contract storage

    constructor(uint256 _count) {
        count = _count;
    }

    function increment() public {
        count += 1;
        console.log("The count value after increment", count);
    }

    function getCount() public view returns (uint256) {
        console.log("The count value on getCount", count);
        return count;
    }
}

How to run the project

Clone the project and go to project directory.

Use npm install to pull in all dependencies.

Solidity code goes into contracts/Counter.sol, tests (Waffle/mocha/chai) go into test/Counter.test.js, Hardhat scripts go into scripts/counter.js.

Use npm run build to compile your contracts.

On compiling the contracts an abi file gets created at artifacts/contracts/Counter.sol/Counter.json. The abi file defines the standard way of interacting with smart contract in the ethereum ecosystem.

compile

Use npm run test:light to run all tests without a coverage report.

Use npm run test to run all tests including a coverage report.

coverage

Use npm run local-testnet to spin up a local Hardhat testnet (Best run this in a separate terminal. It's a long-running process).

Use npm run deploy:local to run scripts/counter.js which deploys the counter contract to your local testnet, previously started with npm run local-testnet.

deploy