PackVRF
Functionality available for contracts that implement the
IPackVRFDirect
interface;
the Chainlink VRF variation of the pack interface.
addPackOpenEventListener
Create an event listener that calls a callback
function whenever a pack is opened on the contract.
const unsubscribe = await contract.vrf.addPackOpenEventListener(
(packId, openerAddress, rewards) => {
console.log(
`Pack ${packId} was opened by ${openerAddress} and contained:, ${rewards})`,
);
},
);
Configuration
callback
The function to run whenever the event is emitted.
Contains three parameters that you can use to access the event data:
packId
- The ID of the pack that was opened.string
.openerAddress
- The address of the account that opened the pack.string
.rewards
- The rewards that were claimed from the pack. Type below:{
erc20Rewards?: {
contractAddress: string;
quantityPerReward: string | number;
}[] | undefined;
erc721Rewards?: {
tokenId: string | number | bigint | BigNumber;
contractAddress: string;
}[] | undefined;
erc1155Rewards?: {
tokenId: string | number | bigint | BigNumber;
contractAddress: string;
quantityPerReward: string | number | bigint | BigNumber;
}[] | undefined;
}
canClaimRewards
Check if a specific wallet can claim rewards after opening a pack.
const canClaim = await contract.vrf.canClaimRewards("{{wallet_address}}");
Configuration
claimRewards
Claim the rewards from an opened pack.
Use canClaimRewards
to check if the wallet can claim rewards before calling this method.
const txResult = await contract.vrf.claimRewards();
getLinkBalance
Get the LINK balance of the contract.
const linkBalance = await contract.vrf.getLinkBalance();
Configuration
Return Value
{
symbol: string;
value: BigNumber;
name: string;
decimals: number;
displayValue: string;
}
open
Open a pack using Chainlink VRFs random number generation.
const result = await contract.vrf.open("{{token_id}}", "{{amount}}");
Configuration
tokenId
The token ID of the pack NFT to open.
Must be a string
, number
, or BigNumber
.
amount (optional)
The amount of packs to open.
If not provided, the default value of 1
will be used.
Must be a string
, number
, or BigNumber
.
Return Value
This function returns a transaction result with the requestId of the open request, not the contents of the pack.
To get the contents of the pack, you must call claimRewards
once the VRF request has been fulfilled
openAndClaim
Open a pack and claim the rewards.
This function will start the flow of opening a pack. The rewards will be granted automatically to the connected address after VRF request is fulfilled.
This is essentially a shortcut for calling open
and claimRewards
in sequence.
const txResult = await contract.vrf.openAndClaim("{{token_id}}", "{{amount}}");
Configuration
tokenId
The token ID of the pack NFT to open.
Must be a string
, number
, or BigNumber
.
amount (optional)
The amount of packs to open.
If not provided, the default value of 1
will be used.
Must be a string
, number
, or BigNumber
.
gasLimit (optional)
The gas limit to use for the VRF callback transaction, defaults to 500000
.
Must be a string
, number
, or BigNumber
.
transferLink
Transfer LINK to this contract.
Note: the wallet that initiates this transaction must have the amount of LINK specified in the amount
parameter.
const txResult = await contract.vrf.transferLink("{{amount}}");