Last active
December 1, 2021 21:52
-
-
Save Olanetsoft/f8ea2716f18a6f9bb7e1fe1fb62b13fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const main = async () => { | |
const coffeeContractFactory = await hre.ethers.getContractFactory( | |
"CoffeePortal" | |
); | |
const coffeeContract = await coffeeContractFactory.deploy({ | |
value: hre.ethers.utils.parseEther("0.1"), | |
}); | |
await coffeeContract.deployed(); | |
console.log("Coffee Contract deployed to:", coffeeContract.address); | |
/* | |
* Get Contract balance | |
*/ | |
let contractBalance = await hre.ethers.provider.getBalance( | |
coffeeContract.address | |
); | |
console.log( | |
"Contract balance:", | |
hre.ethers.utils.formatEther(contractBalance) | |
); | |
/* | |
* Let's try to buy a coffee | |
*/ | |
const coffeeTxn = await coffeeContract.buyCoffee( | |
"This is coffee #1", | |
"idris", | |
ethers.utils.parseEther("0.001") | |
); | |
await coffeeTxn.wait(); | |
/* | |
* Get Contract balance to see what happened! | |
*/ | |
contractBalance = await hre.ethers.provider.getBalance( | |
coffeeContract.address | |
); | |
console.log( | |
"Contract balance:", | |
hre.ethers.utils.formatEther(contractBalance) | |
); | |
let allCoffee = await coffeeContract.getAllCoffee(); | |
console.log(allCoffee); | |
}; | |
const runMain = async () => { | |
try { | |
await main(); | |
process.exit(0); | |
} catch (error) { | |
console.log(error); | |
process.exit(1); | |
} | |
}; | |
runMain(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment