generated from Phala-Network/phat-contract-starter-kit
/
push-request.ts
43 lines (38 loc) · 1.29 KB
/
push-request.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
40
41
42
43
import { ethers } from "hardhat";
import "dotenv/config";
async function main() {
const OracleConsumerContract = await ethers.getContractFactory("OracleConsumerContract");
const [deployer] = await ethers.getSigners();
const consumerSC = process.env["LOCALHOST_CONSUMER_CONTRACT_ADDRESS"] || "";
if (!consumerSC) {
console.error("Error: Please provide LOCALHOST_CONSUMER_CONTRACT_ADDRESS");
process.exit(1);
}
const consumer = OracleConsumerContract.attach(consumerSC);
console.log("Pushing a request...");
await consumer.connect(deployer).request("0xeaf55242a90bb3289db8184772b0b98562053559");
consumer.on("ResponseReceived", async (reqId: number, requester: string, target: string, score: string) => {
console.info("Received event [ResponseReceived]:", {
reqId,
requester,
target,
score,
});
process.exit();
});
consumer.on("ErrorReceived", async (reqId: number, requester: string, target: string, error: string) => {
console.info("Received event [ErrorReceived]:", {
reqId,
requester,
target,
error,
});
process.exit();
});
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});