A sample project for contract deployment and transaction execution using Web3.js.
Designed for COMP4142, Department of Computing, PolyU.
This project demonstrates how to compile a Ethereum Smart Contract using solc
, deploy and invoke contracts using web3.js
.
dotenv: ^16.3.1
solc: ^0.8.21
web3: ^4.1.2
-
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.
-
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.
This repository is released under MIT license. Copyright © Jon.