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:
- An EVM chain endpoint URL
- The chain ID corresponding to your chain
- The private key of an account funded with LINK, and the chain's native token (to pay transaction fees)
- The LINK address, VRF coordinator address, and key hash for your chain
- 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
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:
- An externally owned account (controlled by your private key) initiates a transferAndCall on the LinkToken contract.
- The LinkToken contract transfers funds to the ownerless consumer.
- 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 ¶
There is no documentation for this package.