CRYPTO NEWS

Error Following Tutorial (Login w/ MetaMask)

I’m attempting to follow this Tutorial while converting the code to reactJS but I’m getting a 400 error while trying to get a nonce from the getNonceToSign cloud function. I assume I entered the param data wrong somehow from the front end but idk, I’ve tried every way possible to my knowledge…

Front-End:

const toHex = (stringToConvert) =>   stringToConvert       .split("")       .map((c) => c.charCodeAt(0).toString(16).padStart(2, "0"))       .join("");  const signInWithMetaMask = async () => {      if (!window.ethereum.isMetaMask) {         throw new Error('Please install MetaMask');       }     await console.log(window.ethereum.request({method: 'eth_requestAccounts'}));     // Step 2: Retrieve the current nonce for the requested address     const jsonData = await JSON.stringify([{address: window.ethereum.selectedAddress}])      */// Fetch causes ERROR!!!!!*      await fetch('https://us-central1-app.cloudfunctions.net/getNonceToSign', {         method: 'POST',          mode: 'cors',          body: jsonData // body data type must match "Content-Type" header         }).then(async (response) => {         await console.log(response)         await window.ethereum.request({           method: 'personal_sign',           params: [             `0x${toHex(response.nonce)}`,             window.ethereum.selectedAddress,           ],         })       }).then(async (sig) => {         const jsonData2 = JSON.stringify([{ address: window.ethereum.selectedAddress, signature: sig }])         await fetch('https://us-central1-app.cloudfunctions.net/verifySignedMessage', {         method: 'POST',          mode: 'cors',          body: jsonData2 // body data type must match "Content-Type" header         })}).then(async (response) => {         await signInWithCustomToken(auth, response.token)       }) } 

Back-end Firebase Cloud Functions:

const functions = require("firebase-functions"); const firebaseAdmin = require("firebase-admin"); const cors = require("cors")({origin: true}); const recoverPersonalSignature = require("@metamask/eth-sig-util");   const admin = firebaseAdmin.initializeApp();   exports.getNonceToSign = functions.https.onRequest((request, response) =>   cors(request, response, async () => {     try {       if (request.method !== "POST") {         return response.sendStatus(403);       }       if (!request.body.address) {         return response.sendStatus(400);       }       // Get the user document for that address       const userDoc = await admin           .firestore()           .collection("users")           .doc(request.body.address)           .get();       if (userDoc.exists) {         // The user document exists already, so just return the nonce         const existingNonce = userDoc.data()?.nonce;         return response.status(200).json({nonce: existingNonce});       } else {         // The user document does not exist, create it first         const generatedNonce = Math.floor(Math.random() * 1000000).toString();         // Create an Auth user         const createdUser = await admin.auth().createUser({           uid: request.body.address,         });         // Associate the nonce with that user         await admin.firestore().collection("users").doc(createdUser.uid).set({           nonce: generatedNonce,         });         return response.status(200).json({nonce: generatedNonce});       }     } catch (err) {       console.log(err);       return response.sendStatus(500);     }   }), ); 

What’s the recommended way to allow users to mint random ERC-721 tokens, reveal metadata, and offer full transparency in 2022?

I’m writing an ERC-721 contract to launch a collection of paintings and I’m considering a few semi-generative variations to make the total supply about 1,000 tokens with multiple rarities. I’d like to use a reveal step so that collectors will only know what random token and rarity they get after the collection has sold out::Listen

I’m writing an ERC-721 contract to launch a collection of paintings and I’m considering a few semi-generative variations to make the total supply about 1,000 tokens with multiple rarities.

I’d like to use a reveal step so that collectors will only know what random token and rarity they get after the collection has sold out or some time has passed but I’m slightly confused about the use of a provenance hash and the randomness mechanism.

The short version question is: What’s the recommended way to allow users to mint random tokens, reveal metadata, and offer full transparency in 2022?

And here’s the long version.

Of course I want to offer transparency so I learned all I could about the provenance hash and I’m considering generating the hash with the actual metadata (hashing the full JSON files including the IPFS CID for images instead of just the images, is that somehow better or just unnecessary?) before the sale starts but only pointing to placeholder images at first and then uploading the final metadata and images and setting the baseURI on reveal time.

But I’m not sure about the random part. I’ve read about the BAYC approach with a startingIndex (which apparently the contract doesn’t use correctly) coming from the block number of the last token minted but I’m not sure if that’s still a good approach in 2022. As it looks like BAYC is not a great example of this approach I’d appreciate it if you could point me to a contract doing it the right way.

I initially thought about randomizing the token ID on mint with a Chainlink VRF call but with many tokens that would be too expensive.

Another option I considered was just making one call to Chainlink VRF on reveal and then expanding that number using the random number with keccak256 and them modulo operator to shuffle the token IDs and run a loop over all the tokens calling _setTokenURI to point each token to a JSON metadata file on IPFS. For this to work fine I suppose I shouldn’t put these files in just one IPFS directory so each CID would be different and unrelated to the token ID but I worry that this solution may be too expensive because of the loop and calls to _setTokenURI.

For reference here are a couple of URLs I’ve already explored.

Random-order minting of ERC721 tokens

https://forum.openzeppelin.com/t/are-nft-projects-doing-starting-index-randomization-and-provenance-wrong-or-is-it-just-me/14147/7

Error Following Tutorial (Login w/ MetaMask)

Shopping cart
There are no products in the cart!
Continue shopping
0