CRYPTO NEWS

CORS error on accessing web3.storage IPFS gateway

I’m trying to display files stored on IPFS via web3.storage like this in my front end application:

const makeGatewayURL = (cid, path) => {   return `https://${cid}.ipfs.dweb.link/${encodeURIComponent(path)}` } const getImageMetadata = async (cid) => {   try{     const url = makeGatewayURL(cid, 'metadata.json')     const res = await fetch(url)     if (!res.ok) {       console.log(res)       throw new Error(`error fetching image metadata: [${res.status}] ${res.statusText}`)     }     const metadata = await res.json()     const gatewayURL = makeGatewayURL(cid, metadata.path)     const uri = `ipfs://${cid}/${metadata.path}`     return { ...metadata, cid, gatewayURL, uri }   }   catch (e) {     console.log(e)   } } 

Unfortunately, this is giving me a CORS error.

Is there a better way to do this?

Time dependent contract test in hardhat

I am trying to test a contract in which every 4 minutes the price of token is changing. But I am not able to test the contract as I am unable to manipulate the time.The test without time manipulations are running fine but I have no idea about the time manipulation in hardhat. please help.::Listen

I am trying to test a contract in which every 4 minutes the price of token is changing. But I am not able to test the contract as I am unable to manipulate the time.The test without time manipulations are running fine but I have no idea about the time manipulation in hardhat. please help. Here is the code.

const { expect } = require("chai"); const { ethers } = require("hardhat"); const {helpers}= require ("@nomicfoundation/hardhat-network-helpers"); console.log(mine)  describe("Token contract", function () {     it("Deployment should assign the total supply of tokens to itself", async function () {         const [owner] = await ethers.getSigners();          const Token = await ethers.getContractFactory("Token");          const token = await Token.deploy();          const contractBalance = await token.balanceOf(token.address);         expect(await token.totalSupply()).to.equal(contractBalance);     });      it("buyer can buy the token", async function () {         const [owner, buyer] = await ethers.getSigners();         const Crowdsale = await ethers.getContractFactory("Crowdsale");         const crowdsale = await Crowdsale.deploy();          const Token = await ethers.getContractFactory("Token");         const token = await Token.deploy();          await crowdsale.setTokenAddress(token.address);         await token.approveContract(crowdsale.address);         await crowdsale.setStart();          await crowdsale.connect(buyer).buyToken({ value: ethers.utils.parseEther("1") })         expect(await token.balanceOf(buyer.address)).to.equal("1000000000000000000000")     })      it("Prices should change accoording to time", async function () {         const [owner, buyer] = await ethers.getSigners();         const Crowdsale = await ethers.getContractFactory("Crowdsale");         const crowdsale = await Crowdsale.deploy();          const Token = await ethers.getContractFactory("Token");         const token = await Token.deploy();          await crowdsale.setTokenAddress(token.address);         await token.approveContract(crowdsale.address);         await crowdsale.setStart();                  await helpers.time.increase(240);          await crowdsale.connect(buyer).buyToken({ value: ethers.utils.parseEther("1") })         expect(await token.balanceOf(buyer.address)).to.equal("1000000000000000000000")          await helpers.time.increase(240);         await crowdsale.connect(buyer).buyToken({ value: ethers.utils.parseEther("1") })         expect(await token.balanceOf(buyer.address)).to.equal("500000000000000000000")          await helpers.time.increase(240);         await crowdsale.connect(buyer).buyToken({ value: ethers.utils.parseEther("1") })         expect(await token.balanceOf(buyer.address)).to.equal("200000000000000000000")        })   }); 

Here is the error.enter image description here

CORS error on accessing web3.storage IPFS gateway

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