{"id":27618013,"url":"https://github.com/bisonai/vrf-consumer","last_synced_at":"2025-04-23T04:59:06.956Z","repository":{"id":65898448,"uuid":"592210796","full_name":"Bisonai/vrf-consumer","owner":"Bisonai","description":"Developer guide for VRF in Orakl Network","archived":false,"fork":false,"pushed_at":"2024-06-12T05:30:17.000Z","size":156,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T04:59:01.493Z","etag":null,"topics":["blockchain","klaytn","oracle","orakl","orakl-network","verifiable-randomness-function","vrf","web3"],"latest_commit_sha":null,"homepage":"https://orakl.network","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bisonai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-23T08:01:45.000Z","updated_at":"2024-12-02T08:20:03.000Z","dependencies_parsed_at":"2024-06-07T07:40:48.467Z","dependency_job_id":null,"html_url":"https://github.com/Bisonai/vrf-consumer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bisonai%2Fvrf-consumer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bisonai%2Fvrf-consumer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bisonai%2Fvrf-consumer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bisonai%2Fvrf-consumer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bisonai","download_url":"https://codeload.github.com/Bisonai/vrf-consumer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250372922,"owners_count":21419722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","klaytn","oracle","orakl","orakl-network","verifiable-randomness-function","vrf","web3"],"created_at":"2025-04-23T04:59:06.499Z","updated_at":"2025-04-23T04:59:06.947Z","avatar_url":"https://github.com/Bisonai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VRF Consumer\n\nConsumer smart contract that utilizes VRF functionality from [Orakl Network](https://www.orakl.network).\n\nInternally, the scripts access following smart contracts:\n\nBaobab\n\n- `Prepayment` ([0x8d3A1663d10eEb0bC9C9e537e1BBeA69383194e7](https://baobab.klaytnfinder.io/account/0x8d3A1663d10eEb0bC9C9e537e1BBeA69383194e7))\n- `VRFCoordinator` ([0xDA8c0A00A372503aa6EC80f9b29Cc97C454bE499](https://baobab.klaytnfinder.io/account/0xDA8c0A00A372503aa6EC80f9b29Cc97C454bE499))\n\nCypress\n\n- `Prepayment` ([0xc2C88492Cf7e5240C3EB49353539E75336960600](https://www.klaytnfinder.io/account/0xc2C88492Cf7e5240C3EB49353539E75336960600))\n- `VRFCoordinator` ([0x3F247f70DC083A2907B8E76635986fd09AA80EFb](https://www.klaytnfinder.io/account/0x3F247f70DC083A2907B8E76635986fd09AA80EFb))\n\nIf you want to access different deployments of `Prepayment` or `VRFCoordinator`, you can change it inside `hardhat.config.ts` in `namedAccounts` property.\n\n## Prerequisites\n\nCreate a copy of `.env.example` file and fill in values for `PROVIDER`, and `MNEMONIC` or `PRIV_KEY` (the difference is explained below) environment variables.\nThese variables will be used for connection to JSON-RPC endpoint, deployment and use of your [`VRFConsumer` smart contract](contracts/VRFConsumer.sol).\n\n```shell\ncp .env.example .env\n```\n\n`PROVIDER` can be set to any JSON-RPC endpoint.\nThe list of free available JSON-RPC endpoint can be found in [official Klaytn documentation](https://docs.klaytn.foundation/content/dapp/rpc-service/public-en#testnet-baobab-public-json-rpc-endpoints).\n\nThis repository supports connection to wallet either through mnemonic or private key.\n\n### Mnemonic\n\n`MNEMONIC` can be generated using [npm mnemonics package](https://www.npmjs.com/package/mnemonics).\n\n```shell\nnpx mnemonics\n```\n\nAfter mnemonic is generated, you need to convert it to public address and fund it with KLAY.\nIf you do not have any KLAY in your account, you cannot deploy smart contracts or make any transactions.\n\nYou can convert your newly generated mnemonic with following hardhat task.\nPlease replace the `[MENONIC]` with your mnemonic.\n\n```shell\nnpx hardhat address --mnemonic [MNEMONIC]\n```\n\nThe script will print out a public address corresponding to your mnemonic.\nThen, you can use this address to receive free KLAY using [Baobab's faucet](https://baobab.wallet.klaytn.foundation/faucet).\n\n### Private key\n\nIf you already have a wallet, you can reuse its private key, and connect to JSON-RPC endpoint with it.\nIn case you use Metamask, read [how to export an account's private key.](https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key).\nAfter you extract private key, store it in `PRIV_KEY` variable inside of `.env` file.\n\n## Installation\n\n```shell\nyarn install\n```\n\n## Compilation\n\n```shell\nyarn compile\n```\n\n## Deploy\n\n```shell\nnpx hardhat deploy --network baobab\n```\n\nIf you are using [orakl-repository](https://github.com/Bisonai/orakl/) to run a local node, you can also deploy this `VRFConsumer` on your local node. The `Prepayment` and `VRFCoordinator` addresses in [hardhat.config.ts](hardhat.config.ts) `namedAccounts` and `keyHash` in [utils.ts](scripts/utils.ts) are configured properly to be used locally.\n\n## Get Estimated Service Fee\n\nPrior to creating an account, you have the option to retrieve the estimated service fee for a single VRF request. To do this, you can run the provided script using the following command:\n\n```shell\nnpx hardhat run scripts/get-estimated-service-fee.ts --network baobab\n```\n\nExecuting the script will provide you with the cost associated with a single VRF request. This information will help you determine the amount you need to fund your account accordingly to meet your specific requirements.\n\n## Create and fund account\n\nThere are two types of payments supported by Orakle Network VRF: **Prepayment** and **Direct Payment**.\n\n**Prepayment** requires user to create account and fund it with KLAY before being able to use it.\nThe script below will create a new account and deposit ` 2.5` KLAY from address corresponding to your mnemonic or private key from `.env` file.\n\nIf you prefer to use Orakl Network VRF without having a long-lasting account, you can use **Direct Payment** method.\nIn such case, you can skip the following command and go directly to **Request VRF with Direct Payment**.\n\n```shell\nnpx hardhat run scripts/create-and-fund-account.ts --network baobab\n```\n\nAfter successfully executing the command above, set the value of environment variable `ACC_ID` inside of `.env` file to account ID that was generated using the script above.\nIf you do not do it, the request for VRF using Prepayment won't be working properly.\nAfter setting the `ACC_ID` in `.env` file, you can move to the next step **Request VRF with Prepayment**.\n\nIf you'd like to use your existing prepayment account, set your account id in the `.env` file and add your deployed consumer to your account by executing the hardhat `addConsumer` task (described in more detail below). Note that providing `account-id` parameter is optional if your account id is already in the `.env` file and `consumer` parameter is also optional if you've deployed your consumer using hardhat under this repository.\n\n## Request \u0026 Read VRF\n\nBefore running following scripts, one must deploy `VRFConsumer` smart contract.\nTo deploy `VRFConsumer`, run `npx hardhat deploy --network baobab`.\n\n### Request VRF with Prepayment\n\n```shell\nnpx hardhat run scripts/request-vrf.ts --network baobab\n```\n\n### Request VRF with Direct Payment\n\n```shell\nnpx hardhat run scripts/request-vrf-direct.ts --network baobab\n```\n\n### Read VRF response\n\n```shell\nnpx hardhat run scripts/read-vrf.ts --network baobab\n```\n\n## Hardhat tasks\n\nThe following tasks allow for more finer control over experimentation with the example code in this repository.\n\n### Create a new account\n\n```shell\nnpx hardhat createAccount --network baobab\n```\n\n### Deposit to an account\n\nAfter you have created an account, you can deposit $KLAY to it anytime using the command below.\n\n```shell\nnpx hardhat deposit \\\n    --account-id $ACCOUNT \\\n    --amount $AMOUNT \\\n    --network $NETWORK\n```\n\n### Withdraw from an account\n\nTo withdraw the remaining balance from an account, you can use the command below.\n\n```shell\nnpx hardhat withdraw \\\n    --account-id $ACCOUNT \\\n    --amount $AMOUNT \\\n    --network $NETWORK\n```\n\n### Add a consumer\n\nAdd consumer contract to account.\nThen, the consumer contract will be able to request for VRF service.\n\n```shell\nnpx hardhat addConsumer \\\n    --consumer $CONSUMERADDRESS \\\n    --account-id $ACCOUNT \\\n    --network $NETWORK\n```\n\n### Remove a consumer\n\nRemove a consumer contract from an account.\nThen, the consumer contract will not be able to request for VRF service anymore.\n\n```shell\nnpx hardhat removeConsumer \\\n    --consumer ${CONSUMERADDRESS} \\\n    --account-id ${ACCOUNT} \\\n    --network ${NETWORK}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbisonai%2Fvrf-consumer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbisonai%2Fvrf-consumer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbisonai%2Fvrf-consumer/lists"}