forked from pcaversaccio/hardhat-project-template-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interact.ts
38 lines (30 loc) · 1.15 KB
/
interact.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// An example script that shows how to interact programmatically with a deployed contract
// You must customise it according to your contract's specifications
import { ethers } from "hardhat";
async function main() {
const contract = await ethers.getContractFactory("Greeter"); // Specify here your contract name
const address = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; // Specify here your contract address
////////////////
// PAYLOAD //
//////////////
const newGreeting = "Buongiorno!"; // Specify here the payload of the to-be-called function
///////////////
// ATTACH //
/////////////
const Contract = contract.attach(address);
////////////////
// SENDING //
//////////////
const tx = await Contract.setGreeting(newGreeting); // Specify here the to-be-called function name
console.log("The transaction hash is:", tx.hash);
const receipt = await tx.wait();
console.log(
"The transaction returned the following transaction receipt:\n",
receipt,
);
}
// To run it, invoke `npx hardhat run scripts/interact.ts --network <network_name>`
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});