This project shows how to interact with a simple smart contract in Ethereum blockchain using the ether.js library.
-
Solidity: Programming language for writing smart contratcs.
-
ethers.js: JavaScript library used to interact with Ethereum blockchain.
-
Ganache: Local Ethereum Network to development and tests.
-
Node.js: JavaScript runtime environment.
-
fs-extra: Library to file management.
-
dotenv: For securely managing environment variables.
This project consists of a simple Solidity smart contract that lets you store and retrieve a single number. The JavaScript script, written with ethers.js, performs the following operations:
-
Connects to a local Ethereum network (Ganache).
-
Loads the contract's ABI and bytecode.
-
Deploys the contract to the blockchain.
-
Interacts with the contract by calling the store function to update the number.
-
Retrieves the updated number to verify that the transaction was successful.
Node.js installed.
Ganache Desktop installed and running on the default port (or a port you configure).
A .env file in the project's root directory with your private key: PRIVATE_KEY=your-private-key-here.
Steps 1 - Clone this repository or create the file structure.
2- Install the dependencies:
npm install
Compile the SimpleStorage.sol contract (using solc or Hardhat, for example) to generate the .abi and .bin files.
Run the deploy script:
node deploy.js