Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit bbf1e12

Browse files
committed
add interaction script
1 parent 68f6977 commit bbf1e12

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/greet.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const hre = require("hardhat");
2+
const ContractJson = require("../artifacts/contracts/Greeter.sol/Greeter.json");
3+
const abi = ContractJson.abi;
4+
5+
async function main() {
6+
const alchemy = new hre.ethers.providers.AlchemyProvider('maticmum', process.env.ALCHEMY_API_KEY);
7+
const userWallet = new hre.ethers.Wallet(process.env.PRIVATE_KEY, alchemy);
8+
9+
// Get the deployed contract.
10+
const Greeter = new hre.ethers.Contract(process.env.CONTRACT_ADDRESS, abi, userWallet)
11+
12+
const setTx1 = await Greeter.setGreeting("web3 sucks!");
13+
await setTx1.wait();
14+
console.log("before: " + await Greeter.greet());
15+
16+
const setTx2 = await Greeter.setGreeting("web3 is awesome!");
17+
await setTx2.wait();
18+
console.log("after: " + await Greeter.greet());
19+
}
20+
21+
// We recommend this pattern to be able to use async/await everywhere
22+
// and properly handle errors.
23+
main()
24+
.then(() => process.exit(0))
25+
.catch((error) => {
26+
console.error(error);
27+
process.exit(1);
28+
});

0 commit comments

Comments
 (0)