Skip to content

Instantly share code, notes, and snippets.

@Olanetsoft
Last active December 1, 2021 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Olanetsoft/f8ea2716f18a6f9bb7e1fe1fb62b13fe to your computer and use it in GitHub Desktop.
Save Olanetsoft/f8ea2716f18a6f9bb7e1fe1fb62b13fe to your computer and use it in GitHub Desktop.
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