The goal of this project is to Emit the winner event on this Alchemy smart contract on the Goerli testnet:
https://goerli.etherscan.io/address/0xcF469d3BEB3Fc24cEe979eFf83BE33ed50988502#code
If you take a look at the code tab, you'll see that the source code for this contract looks like this:
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract Contract {
event Winner(address);
function attempt() external {
require(msg.sender != tx.origin, "msg.sender is equal to tx.origin");
emit Winner(msg.sender);
}
}
-
Contract deployment via Hardhat
-
Contract interaction
-
Difference between msg.sender and tx.origin.
- Install dependencies:
npm i -D hardhat -- yes to all
npm i dotenv
- Deploy your contract in Goerli Testnet:
npx hardhat run scripts/deploy.js --network goerli
- Replace the variable CONTRACT_ADDRESS in the script triggerWinner.js with your deployed contract address and run:
npx hardhat run scripts/triggerWinner.js --network goerli
- DONE
P.S: You should see an event emitted on the Alchemy smart contract address above: