├── .gitignore ├── README.md ├── package.json ├── hardhat.config.js ├── scripts ├── manage-pause.js ├── manage-owner.js ├── deploy.js ├── withdraw.js └── buy-coffee.js ├── contracts └── BuyMeACoffee.sol └── test └── Lock.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | coverage 4 | coverage.json 5 | typechain 6 | typechain-types 7 | 8 | #Hardhat files 9 | cache 10 | artifacts 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sample Hardhat Project 2 | 3 | This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. 4 | 5 | Try running some of the following tasks: 6 | 7 | ```shell 8 | npx hardhat help 9 | npx hardhat test 10 | GAS_REPORT=true npx hardhat test 11 | npx hardhat node 12 | npx hardhat run scripts/deploy.js 13 | ``` 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "buymeacoffee-contracts", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@nomicfoundation/hardhat-chai-matchers": "^1.0.2", 14 | "@nomicfoundation/hardhat-toolbox": "^1.0.2", 15 | "@nomiclabs/hardhat-ethers": "^2.1.0", 16 | "ethers": "^5.6.9", 17 | "hardhat": "^2.10.1" 18 | }, 19 | "dependencies": { 20 | "@nomiclabs/hardhat-waffle": "^2.0.3", 21 | "dotenv": "^16.0.1", 22 | "ethereum-waffle": "^3.4.4" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hardhat.config.js: -------------------------------------------------------------------------------- 1 | //require("@nomicfoundation/hardhat-toolbox"); 2 | require("@nomiclabs/hardhat-ethers"); 3 | require("@nomiclabs/hardhat-waffle"); 4 | //require("@nomicfoundation/hardhat-chai-matchers"); 5 | require("dotenv").config() 6 | 7 | // You need to export an object to set up your config 8 | // Go to https://hardhat.org/config/ to learn more 9 | 10 | const GOERLI_URL = process.env.GOERLI_URL; 11 | const PRIVATE_KEY = process.env.PRIVATE_KEY; 12 | 13 | 14 | 15 | /** 16 | * @type import('hardhat/config').HardhatUserConfig 17 | */ 18 | module.exports = { 19 | solidity: "0.8.9", 20 | networks: { 21 | goerli: { 22 | url: [GOERLI_URL] , 23 | accounts: [PRIVATE_KEY] 24 | } 25 | } 26 | 27 | }; 28 | 29 | 30 | -------------------------------------------------------------------------------- /scripts/manage-pause.js: -------------------------------------------------------------------------------- 1 | const hre = require("hardhat"); 2 | 3 | async function getContract() { 4 | const BuyMeACoffee = await hre.ethers.getContractFactory("BuyMeACoffee"); 5 | const buyMeACoffee = await BuyMeACoffee.attach( 6 | "YOUR_DEPLOYED_CONTRACT_ADDRESS" // TODO: Replace with your deployed contract address 7 | ); 8 | return buyMeACoffee; 9 | } 10 | 11 | async function main() { 12 | const buyMeACoffee = await getContract(); 13 | 14 | console.log("Current paused status:", await buyMeACoffee.paused()); 15 | 16 | // To pause the contract: 17 | // const pauseTx = await buyMeACoffee.pause(); 18 | // await pauseTx.wait(); 19 | // console.log("Contract paused."); 20 | 21 | // To unpause the contract: 22 | // const unpauseTx = await buyMeACoffee.unpause(); 23 | // await unpauseTx.wait(); 24 | // console.log("Contract unpaused."); 25 | 26 | console.log("New paused status:", await buyMeACoffee.paused()); 27 | } 28 | 29 | main() 30 | .then(() => process.exit(0)) 31 | .catch((error) => { 32 | console.error(error); 33 | process.exit(1); 34 | }); 35 | -------------------------------------------------------------------------------- /scripts/manage-owner.js: -------------------------------------------------------------------------------- 1 | const hre = require("hardhat"); 2 | 3 | async function getContract() { 4 | const BuyMeACoffee = await hre.ethers.getContractFactory("BuyMeACoffee"); 5 | const buyMeACoffee = await BuyMeACoffee.attach( 6 | "YOUR_DEPLOYED_CONTRACT_ADDRESS" // TODO: Replace with your deployed contract address 7 | ); 8 | return buyMeACoffee; 9 | } 10 | 11 | async function main() { 12 | const buyMeACoffee = await getContract(); 13 | const [owner] = await hre.ethers.getSigners(); 14 | 15 | console.log("Current owner:", await buyMeACoffee.owner()); 16 | 17 | // To transfer ownership to a new address (replace NEW_OWNER_ADDRESS): 18 | // const newOwnerAddress = "NEW_OWNER_ADDRESS"; 19 | // const transferTx = await buyMeACoffee.connect(owner).updateOwner(newOwnerAddress); 20 | // await transferTx.wait(); 21 | // console.log(`Ownership transferred to ${newOwnerAddress}`); 22 | 23 | console.log("New owner (after potential transfer):", await buyMeACoffee.owner()); 24 | } 25 | 26 | main() 27 | .then(() => process.exit(0)) 28 | .catch((error) => { 29 | console.error(error); 30 | process.exit(1); 31 | }); 32 | -------------------------------------------------------------------------------- /scripts/deploy.js: -------------------------------------------------------------------------------- 1 | // We require the Hardhat Runtime Environment explicitly here. This is optional 2 | // but useful for running the script in a standalone fashion through `node