Hi everyone, I’m having a problem when I try to read from the blockchain. Sometimes I get this error: header CORS Access-Control-Allow-Origin is missing. This happen when I read from the blockchain with the PureStake credentials. But the strange think is that this problem don’t show up every time, but only sometimes. If i try to refresh the page is possible that the next execution goes all ok without problem, or is possible that I receive again the error. How can I resolve this problem? I’m using Laravel and Heroku. The problem is present if I run the site on localhost and if I run the site on Heroku.
Hey - shoot me a note letting me know which call (endpoint) you are making when that happens. I suspect one of the error responses is not properly configured.
The main issue here was calling a v2 path with a v1 client or vice versa. We added a sample HTML file that declares a v1, v2, and Indexer client to our API samples repo.
A snippet:
const legacyServer = "https://testnet-algorand.api.purestake.io/ps1";
const newServer = "https://testnet-algorand.api.purestake.io/ps2";
const indexServer = "https://testnet-algorand.api.purestake.io/idx2";
const port = "";
const token = { 'X-API-key' : 'YOUR KEY HERE'}
let algodClient = new algosdk.Algod(token, legacyServer, port);
let algodClientV2 = new algosdk.Algodv2(token, newServer, port);
let indexerClient = new algosdk.Indexer(token, indexServer, port);
The thing is that I’m testing from browser using JS SDK… this code was working by running the local node. But now I see that assets api from purestake is not going with Algod, but from indexer. Thus main url is different and querying assets didn’t work.
It’s perfectly fine that you’re testing it from within the browser. In that case, try to open the browser developer console and looks for the response headers for the above request, and (maybe) compare it with the one you would get from the node directly.
( if you were to have this issue on one of the other SDKs, I would suggest trying Wireshark… )
If you could identify which headers are missing, it would be extremely helpful.
Correct @Tim I would be happy to help on identifying the problem @tsachi . But in this case, I think there is no issue, as I was trying to use /ps2 for asset endpoints. Which later I saw is going through Indexer.
Although, I guess the response should be 404 instead of displaying CORS error?