wurahara / Lab5-web3

Lab 5 for COMP4142.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lab5-web3

A sample project for contract deployment and transaction execution using Web3.js.

Designed for COMP4142, Department of Computing, PolyU.

Preface

This project demonstrates how to compile a Ethereum Smart Contract using solc, deploy and invoke contracts using web3.js.

Dependency

dotenv:   ^16.3.1
solc:     ^0.8.21
web3:     ^4.1.2

Deployment

  • Run the image to initiate a container:

    $ docker run -d --rm --name web3 \
        -it crumblejon/smart-contract-web3

    This will pull the image crumblejon/smart-contract-web3 from Docker Hub and run it in Docker.

  • Configure your API key and private key by:

    $ docker exec web3 \
        npm run secret \
        <your_API_key> <your_private_key>
    

    You can get an API key from Infura, and find your private key from the MetaMask extension.

Execution

  • Deploying the Incrementor.sol smart contract:

    $ docker exec web3 \
        npm run deploy

    This will deploy the contract to Sepolia Test Network, and return its address on the blockchain.

  • Increment the counter by a certain value:

    $ docker exec web3 \
        npm run increment \
        <contract_address> <value>

    This will add a value to the counter in the contract.

  • Check the counter state in the contract:

    $ docker exec web3 \
        npm run counter \
        <contract_address>
  • Reset the counter value to a certain value:

    $ docker exec web3 \
        npm run reset \
        <contract_address> <value>

    This will reset the counter value in the contract to the given value.

License

This repository is released under MIT license. Copyright © Jon.

About

Lab 5 for COMP4142.

License:MIT License


Languages

Language:JavaScript 87.8%Language:Solidity 9.7%Language:Dockerfile 2.5%