# Switchboard V2 VRF Kriss practicing note. This is the Switchboard V2 VRF Example practicing note by Kriss, Switchboard VRF V2 is the first verfied on-chain randomness oracel on Solana built by Switchboard team. ## Switchboard V2 VRF Example An example repo demonstrating the usage of the Switchboard V2 VRF invoking an example program when a new randomness request is fulfilled. See [docs.switchboard.xyz/randomness](https://docs.switchboard.xyz/randomness) for a full explanation of the Switchboard VRF. ## Dependencies You will need the following installed - [Node and NPM](https://github.com/nvm-sh/nvm#installing-and-updating) - [Docker Compose](https://docs.docker.com/compose/install) - [Rust](https://www.rust-lang.org/tools/install) - [Solana](https://docs.solana.com/cli/install-solana-cli-tools) - [Anchor](https://project-serum.github.io/anchor/getting-started/installation.html#install-anchor) ## Install ```bash git clone https://github.com/switchboard-xyz/vrf-cpi-example.git cd vrf-cpi-example npm install anchor build ``` ![](https://i.imgur.com/vQnR49J.png) Then run `anchor keys list` to get your program ID (PID). Be sure to update the declare_id macro in `programs/anchor-example/src/lib.rs`. Then deploy anchor-example to devnet: ```bash anchor deploy --provider.cluster Devnet ``` ![](https://i.imgur.com/ZmACLbC.png) ## Commands - [Setup Oracle Network](#Setup-Oracle-Network) - [Create Accounts](#Create-Accounts) - [Request Randomness](#Request-Randomness) - [Manually Update State](#Manually-Update-State) - [Read State](#Read-State) - [Watch Account](#Watch-Account) **NOTE:** Each randomness request costs 0.1 wSOL. The following commands assume you use the same keypair, containing an active devnet Solana balance to pay for new accounts, Rename `secrets/payer-keypair.json` to `secrets/program-auth.json`, ```bash solana-keygen new --no-bip39-passphrase --outfile secrets/payer-keypair.json solana airdrop 1 secrets/payer-keypair.json solana airdrop 1 secrets/payer-keypair.json solana airdrop 1 secrets/payer-keypair.json solana airdrop 1 secrets/payer-keypair.json ``` and an associated token wallet with wrapped SOL. ```bash spl-token wrap 1 secrets/payer-keypair.json ``` ### Setup Oracle Network Create an oracle queue and oracle with sufficient permissions, to run a node locally. ``` USAGE $ ts-node src setup --payer [PAYERKEYPAIR] ARGUMENTS OPTIONS --payer filesystem path of keypair file that will pay for, and be authority for, any new accounts EXAMPLE $ ts-node src setup --payer secrets/payer-keypair.json ``` ![](https://i.imgur.com/Zbn1oQ3.png) This will output two commands, one is to start an oracle and listen for VRF randomness requests, another is to create a new VRF Account. Let's run the create a new VRF Account command: ```bash ts-node src create BKJMnmn4NXw4JD6jFmzfswHPmtomYTfqEyc7VqWMAUuR --payer secrets/payer-keypair.json --rpcUrl https://api.devnet.solana.com --cluster devnet ``` ![](https://i.imgur.com/JIH5XDT.jpg) And then run the following command to request a new ranomness value: ```bash ts-node src request ZZkVW3xUz9eXqFBMNssFdXAWSDHeCjpwrChLsdLYZae --payer secrets/payer-keypair.json --rpcUrl https://api.devnet.solana.com --cluster devnet ``` ![](https://i.imgur.com/87XV5jr.png) Your randomness request run successfully.