The Sepolia-Etherscan link that you've attached belongs to the VRFCoordinatorV2 that acts as the Subscription Manager, the UI for the same is available at vrf.chain.link website.
Basically, using this you can create or cancel subscription as well as add or remove consumer to/from a particular subscription that you've created, etc.
Your understanding regarding when to choose a Subscription or Direct Funding, is quite correct.
Subscription is better if you will have recurring random numbers
needed to be generated, hence the term 'subscription'. And because of
this recurrence, you will need to prefund your wallet, rather than
adhoc as one would do with Direct Funding.
You can read more about their different characteristics from Choosing the correct method section of Chainlink VRF docs.
In the subscription that you've created, the consumers are basically the addresses of the contracts that can request random words/numbers depending on the logic implemented in the particular contract, thereby using the funding from your subscription account.
In your implementation, the 2nd step that you've mentioned:
Not sure how I would do this step, how would I make the number
inaccessible to others until the drawing/reading on Sunday? And how in
practice would people verify that the number was generated on Monday?
Would I send them to like an Etherscan link? A link to a page on
Chainlink?
When you're printing a number between 1 and 10 million, say on Monday, then you can note down the timestamp using block.timestamp
that records the current timestamp in seconds, like:
timestampOfNumberPrinting = block.timestamp;
So, if you want to allow the call of a certain function (i.e., drawing/reading) on the coming Sunday (i.e., 6 days after number printing or 6 days after Monday), then you can add a condition to compare the current timestamp with the timestampOfNumberPrinting
, like:
error Lottery__NumberIsNotAccessibleYet();
uint256 private constant SECONDS_IN_ONE_DAY = 86400;
if (block.timestamp < timestampOfNumberPrinting + (6 * SECONDS_IN_ONE_DAY)) {
revert Lottery__NumberIsNotAccessibleYet();
}
And, people can verify that the number was generated/printed on Monday, by checking the value of timestampOfNumberPrinting
. As, the exact day and date can be retrieved from the timestamp on the client side i.e., the frontend of your dApp, somewhat in a similar manner that this Epoch-Converter website is doing.
Here's a sample JS code to get the day from the timestamp:
// Assuming ts is your timestamp in seconds
const timestampInSeconds = 1714981670; // Example timestamp in seconds
// Convert seconds to milliseconds
const timestampInMilliseconds = timestampInSeconds * 1000;
// Create a new Date object using the timestamp in milliseconds
const date = new Date(timestampInMilliseconds);
// Array of day names
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
// Get the day of the week (0-6)
const dayIndex = date.getDay();
// Get the name of the day using the day index
const dayName = days[dayIndex];
console.log("Day:", dayName);