PatrickAlphaC / nft-mix

MIT License
825 stars 414 forks source link

VRF Coordinator v2 - sepolia #112

Closed ReasonZx closed 1 year ago

ReasonZx commented 1 year ago

The code has been adapted to work on the new Ethereum testnet - Sepolia and to work with the new Chainlink subscription method - VRF Coordinator v2.

For each new project a new subscription Id should be created following https://docs.chain.link/vrf/v2/subscription/

Also, I believe this should be merged on a separate branch as changes are too many to make it compatible with older Ethereum testnets.

hasan6-9 commented 1 year ago

@PatrickAlphaC, @ReasonZx can you please explain all the changes I need to make in detail, step by step? Because I am still not able to deploy scripts related to "advanced_collectible" and I am not able to completely understand what to do from the referred link as it requires new parameters in requestRandomWords() functions which I am not aware of how to set.

PatrickAlphaC commented 1 year ago

Wow thanks so much! Can we update the readme too?

ReasonZx commented 1 year ago

Hey @hasan6-9 ,

If you try to follow the video but using Sepolia testnet you soon find that the VRFCoordinator v1 (the one used in the video) is not supported on Sepolia. (https://docs.chain.link/vrf/v1/supported-networks)

The other Ethereum testnets are being discountinued, which is why I went on with Sepolia and learned to use the VRFCoordinator v2.

How to move from v1 to v2 is explained here: https://docs.chain.link/vrf/v2/subscription/migration-from-v1 But basically there is one "concept" that is significantly different from the v2 to v1: In v1 you used to directly fund the SmartContract, i.e. directly send $link to the contract. In v2, instead, you will have to create a "subscription". To do so you can go to this link https://vrf.chain.link/sepolia. Once you create a subscription you will have to send some $link to that subscription (on the same webpage) and you will be given a subscriptionID. Then you add the subscritpionID on the brownie-config file and finally once you deploy the SmartContract you will have to add the address of your SmartContract as a "consumer" of your subscription - also on the same webpage.

Other than that the functions used have different names, but operate in the same way. requestRandomness() now becomes requestRandomWords(). You can see here the header of that function (https://github.com/smartcontractkit/chainlink/blob/2c21702ba91a0e04babfb87118f70b9f47942bbb/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol#L346C1-L346C1), but the only important difference is that now you can request more than just 1 number in a single call and you also have to send your subscriptionID. Then instead of the fulfillRandomness() you will have the fulfillRandomWords() which is basically the same but instead of the random number being just a uint256 now it is an array of uint256 because you can request more than just one random number.

And thats basically all the changes that there are. The rest are just version upgrades which are needed to work with VRF v2 such as solidity v.0.8.0 instead of v0.6.0 and OpenZeppelin v4.1.0 instead of v3.4.0.

ReasonZx commented 1 year ago

Sure @PatrickAlphaC , will do so.

ReasonZx commented 1 year ago

Updated @PatrickAlphaC

PatrickAlphaC commented 1 year ago

Wow thank you so much!!!

PatrickAlphaC commented 1 year ago

@ReasonZx are you on twitter? I'll follow you

ReasonZx commented 1 year ago

@ReasonZx are you on twitter? I'll follow you

Hey @PatrickAlphaC awesome 🤩 twitter.com/ReasonZx