vrfv1

command
v1.12.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 19 Imported by: 0

README

Using the Ownerless Consumer Example

The ownerless consumer example contract allows anyone to request randomness from VRF V1 without needing to deploy their own consuming contract. It does not hold any ETH or LINK; a caller must send it LINK and spend that LINK on a randomness request within the same transaction.

This guide covers requesting randomness and optionally deploying the contract.

Setup

Before starting, you will need:

  1. An EVM chain endpoint URL
  2. The chain ID corresponding to your chain
  3. The private key of an account funded with LINK, and the chain's native token (to pay transaction fees)
  4. The LINK address, VRF coordinator address, and key hash for your chain
  5. Go

The endpoint URL can be a locally running node, or an externally hosted one like alchemy. Your chain ID will be a number corresponding to the chain you pick. For example the Rinkeby testnet has chain ID 4. Your private key can be exported from MetaMask.

Note: Be careful with your key. When using testnets, it's best to use a separate account that does not hold real funds.

Run the following command to set up your environment:

export ETH_URL=<YOUR ETH URL>
export ETH_CHAIN_ID=<YOUR CHAIN ID>
export ACCOUNT_KEY=<YOUR PRIVATE KEY>
export LINK=<LINK ADDRESS>
export COORDINATOR=<COORDINATOR ADDRESS>
export KEY_HASH=<KEY HASH>

Now "cd" into the VRF V1 scripts directory:

cd <YOUR LOCAL CHAINLINK REPO>/core/scripts/vrfv1

Getting a Consumer

Since this contract is ownerless, you can use an existing instance instead of deploying your own. To use an existing instance, copy the command corresponding to the chain you want to use below, otherwise go to the deployment section.

Once you have chosen or deployed a consumer, run:

export CONSUMER=<YOUR CONSUMER ADDRESS>
Existing Consumers
Testnets
Ethereum Rinkeby Testnet

0x1b7D5F1bD3054474cC043207aA1e7f8C152d263F

BSC Testnet

0x640F2D8fd734cb53a6938CeC4CfC0543BbcC0348

Polygon Mumbai Testnet

0x640F2D8fd734cb53a6938CeC4CfC0543BbcC0348

Deploying a New Consumer

To deploy the contract, run:

go run main.go ownerless-consumer-deploy --coordinator-address=$COORDINATOR --link-address=$LINK

You should see output like:

Ownerless Consumer: <YOUR CONSUMER ADDRESS> TX Hash: <YOUR TX HASH>

Requesting Randomness

Since the ownerless consumer does not hold LINK funds, it can only request randomness through a transferAndCall from the LINK contract. The transaction has the following steps:

  1. An externally owned account (controlled by your private key) initiates a transferAndCall on the LinkToken contract.
  2. The LinkToken contract transfers funds to the ownerless consumer.
  3. The ownerless consumer requests randomness from the VRF Coordinator, using the LINK from step 2 to pay for it.

To request randomness for your chosen consumer, run:

go run main.go ownerless-consumer-request --link-address=$LINK --consumer-address=$CONSUMER --key-hash=$KEY_HASH

You should see the output:

TX Hash: <YOUR TX HASH>

You can put this transaction hash into a block explorer to check its progress. Shortly after it's confirmed, usually only a few minutes, you should see a second incoming transaction to your consumer containing the randomness result.

Debugging Reverted Transactions

A reverted transaction could have number of root causes, for example insufficient funds / LINK, or incorrect contract addresses.

Tenderly can be useful for debugging why a transaction failed. For example this Rinkeby transaction failed because a non-owner tried to request random words from VRFExternalSubOwnerExample.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL