-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { ethers } from 'hardhat' | ||
import { getKeyHash } from './utils' | ||
import { Prepayment__factory } from '@bisonai/orakl-contracts' | ||
import hre from 'hardhat' | ||
import { readFileSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
const ACC_ID = process.env.ACC_ID | ||
|
||
async function createContracts(count: number) { | ||
const { getNamedAccounts } = hre | ||
const { vrfCoordinator, prepayment: prepaymentAddress } = await getNamedAccounts() | ||
const prepayment = await ethers.getContractAt(Prepayment__factory.abi, prepaymentAddress) | ||
|
||
const VRFConsumerFactory = await ethers.getContractFactory('VRFConsumer') | ||
|
||
const contracts = [] | ||
for (let i = 0; i < count; i++) { | ||
const userContract = await VRFConsumerFactory.deploy(vrfCoordinator) | ||
await userContract.deployed() | ||
contracts.push(userContract.address) | ||
|
||
await (await prepayment.addConsumer(ACC_ID, userContract.address)).wait() | ||
} | ||
|
||
return contracts | ||
} | ||
|
||
async function requestRandomWords(contracts: string[]) { | ||
const path = join(__dirname, '../deployments/localhost/VRFConsumer.json') | ||
const VRFConsumerABI = JSON.parse(readFileSync(path, 'utf-8')).abi | ||
for (const contractAddr of contracts) { | ||
const keyHash = getKeyHash() | ||
const callbackGasLimit = 500_000 | ||
const numWords = 1 | ||
|
||
const contract = await ethers.getContractAt(VRFConsumerABI, contractAddr) | ||
await contract.requestRandomWords(keyHash, ACC_ID, callbackGasLimit, numWords) | ||
} | ||
} | ||
|
||
async function readRandomwords(contracts: string[]) { | ||
const path = join(__dirname, '../deployments/localhost/VRFConsumer.json') | ||
const VRFConsumerABI = JSON.parse(readFileSync(path, 'utf-8')).abi | ||
for (const contractAddr of contracts) { | ||
const contract = await ethers.getContractAt(VRFConsumerABI, contractAddr) | ||
const randomWord = await contract.sRandomWord() | ||
console.log(`${contract.address} randomWord ${randomWord.toString()}`) | ||
} | ||
} | ||
|
||
async function main() { | ||
// const contracts = await createContracts(5) | ||
// console.log(contracts) | ||
const contracts = [ | ||
'0x8A791620dd6260079BF849Dc5567aDC3F2FdC318', | ||
'0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e', | ||
'0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82', | ||
'0x0B306BF915C4d645ff596e518fAf3F9669b97016', | ||
'0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE' | ||
] | ||
// await requestRandomWords(contracts) | ||
await readRandomwords(contracts) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters