This Reactjs application allows users to interact with an Ethereum smart contract by unlocking it using a password stored in the contract's storage. The application utilizes the MetaMask Web3Provider to connect to the Ethereum blockchain and the ethers library for Ethereum interactions.
Contract Source Code:
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract CTF1 {
bool public locked;
bytes32 private password;
event Winner(address);
constructor(bytes32 _password) {
locked = true;
password = _password;
}
function unlock(bytes32 _password) public {
if (password == _password) {
locked = false;
emit Winner(msg.sender);
}
}
}
-
Clone the repository to your local machine:
git clone https://github.com/bharatbhusal/ctf-challenge.git
-
Install dependencies:
npm install
-
Start the application:
npm start
-
Open your browser and navigate to http://localhost:3000 to view the application.
-
Make sure you have MetaMask installed and connected to the Ethereum network.
-
Click the "Unlock" button to initiate the unlocking process.
-
Update the smart contract address and ABI in the
App.js
file to match your specific contract details:const contract_address = `0x89d5b48f3974A05b4BF816aebA12D401c0ebb003`; const slot = 1; // Modify this according to your contract storage structure.
-
Ensure MetaMask is configured with the correct network and account.
Feel free to contribute by opening issues or submitting pull requests.