-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathuse-greeter.ts
39 lines (28 loc) · 1.4 KB
/
use-greeter.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
39
import * as ethers from "ethers";
import { promises as fs } from "fs";
import { Provider, Wallet } from "zksync-web3";
import { localConfig } from "../../config";
import { Wallets } from "../../entities";
import { Buffer } from "../../entities";
import { Helper } from "../../helper";
import type { HardhatRuntimeEnvironment } from "hardhat/types";
export default async function (hre: HardhatRuntimeEnvironment) {
const bufferRoute = "src/playbook/";
const helper = new Helper();
let contract: any; // eslint-disable-line
const greeterContractAddress = await helper.getStringFromFile(bufferRoute + Buffer.greeterL2);
const provider = new Provider(localConfig.L2Network);
const wallet = new Wallet(Wallets.richWalletPrivateKey, provider);
function getContract(hre: HardhatRuntimeEnvironment, wallet: Wallet) {
const artifact = hre.artifacts.readArtifactSync("Greeter");
contract = new ethers.Contract(greeterContractAddress, artifact.abi, wallet);
return contract;
}
const executeGreetings = getContract(hre, wallet);
const newGreeting = "New Greetings!";
const transaction = await executeGreetings.setGreeting(newGreeting);
const transactionReceipt = await transaction.wait(1);
console.log(`Transaction hash: ${transactionReceipt.transactionHash}`);
await fs.writeFile(Buffer.executeGreeterTx, transactionReceipt.transactionHash);
return transactionReceipt.transactionHash;
}