-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentropy.deploy.ts
More file actions
58 lines (41 loc) · 1.28 KB
/
entropy.deploy.ts
File metadata and controls
58 lines (41 loc) · 1.28 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { ethers } from "hardhat";
const hre = require("hardhat");
const run = async () => {
const [signer] = await ethers.getSigners();
let coinToss;
const coinTossContract = await ethers.getContractFactory("PythCoinFlip");
// Pyth Entropy on Base
// visit https://docs.pyth.network/entropy/contract-addresses to obtain listed chain entrpyb address
const entropy = "0x6E7D74FA7d5c90FEF9F0512987605a6d546181Bb";
coinToss = await coinTossContract.deploy(entropy);
await hre.run("verify:verify", {
address: coinToss.address,
constructorArguments: [entropy],
});
console.log({
coinToss: coinToss.address,
});
await flip(coinToss.address)
};
const hex = ()=>{
const randomBytes = ethers.utils.randomBytes(32); // Generate 32 random bytes
const randomHex = ethers.utils.hexlify(randomBytes);
console.log(randomHex)
return randomHex
}
const flip = async(addy :string)=>{
const d = await ethers.getContractAt("PythCoinFlip",addy)
// visit https://docs.pyth.network/entropy/current-fees
// to get msg.value (fee) requried per blockchain
const fee = 159000000000000n
// head = true, tail = false
const face = true
const _r = await hex()
await d.flipWithPyth(face,_r,{
value: fee
})
}
const main = async () => {
await run ();
};
main();