Why merkleTreeData is promise when I awaited? const merkleTree =…
- User
Why merkleTreeData is promise when I awaited?
const merkleTree = publicKey("F3cH9viZBm8SXmt8FwbMSafrAZgvetUDYhVHSfcjUe9Q"); const merkleTreeData = async () => { return await fetchTreeConfigFromSeeds(umi, { merkleTree }); }; let nftMinted = merkleTreeData.numMinted; let lastUpdated = Date.now();
Assistant
The reason
merkleTreeDatais a promise even after using theawaitkeyword is because you're not awaiting the function call itself. Instead, you're assigning the async function to themerkleTreeDatavariable. To get the resolved value from the promise, you should call the function and await its result. Here's the corrected code:javascriptconst merkleTree = publicKey("F3cH9viZBm8SXmt8FwbMSafrAZgvetUDYhVHSfcjUe9Q"); const fetchMerkleTreeData = async () => { const merkleTreeData = await fetchTreeConfigFromSeeds(umi, { merkleTree }); return merkleTreeData; }; (async () => { const merkleTreeData = await fetchMerkleTreeData(); let nftMinted = merkleTreeData.numMinted; let lastUpdated = Date.now(); // Continue your code here })();In this example, I've created a new async function
fetchMerkleTreeDatathat fetches the data and returns the result. Then, I call this function inside an async IIFE (Immediately Invoked Function Expression) and await its result before accessing thenumMintedproperty.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.