1

'https://sepolia.etherscan.io/address/0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625' Why this Etherscan link specifically? Is it like a Chainlink contract, and then we are writing our own contract to the Chainlink address/ecosystem/contract?

My understanding is that when choosing between a Subscription vs Direct Funding, 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. Is this an accurate characterization?

This is the specific Subscription that I made: https://vrf.chain.link/sepolia/11567 Are consumers individuals who can read/verify the contract and/or subscription?

In practice, if I wanted to have say, a lottery game that printed a number between 1 and 10m on Monday, sell tickets from Tuesday until Saturday, and then read the drawing out on Sunday, are the steps I would take

  1. Modify the code in remix to print out a number between 1-10m

  2. 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?

Thanks

1 Answer 1

1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.