Using algosdk.min.js from Firefox

I have used algosdk.min.js from my Firefox browser, and used the PureStake API to communicate with the blockchain. Recently I have experienced problems with the PureStake testnet interface, so I decided to use the local algod client.

I have generated a token with

goal node generatetoken

Then I tried to communicate using the new token with the local testnet “node”:

Result:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:4001/v2/accounts/WOIX2F25IIRAP3RLXZHINMSSIF2B4WMR3XCQW76KXESN4ZXYB3JF6L3K5Q. (Reason: CORS request did not succeed).

If I try from the browser the line:

http://localhost:4001/v2/accounts/WOIX2F25IIRAP3RLXZHINMSSIF2B4WMR3XCQW76KXESN4ZXYB3JF6L3K5Q

then I get unable to connect.

I also tried

curl http://$(cat ~/n_test1/data_testnet/algod.net)/v1/block/31538 -H "X-Algo-API-Token: $(cat ~/n_test1/data_testnet/algod.token)"

failed to retrieve information from the ledger

Can it be fixed somehow?

Yes:

curl http://$(cat ~/n_test1/data_testnet/algod.net)/v1/status -H "X-Algo-API-Token: $(cat ~/n_test1/data_testnet/algod.token)"
{"lastRound":13661685,"lastConsensusVersion":"https://github.com/algorandfoundation/specs/tree/3a83c4c743f8b17adfd73944b4319c25722a6782","nextConsensusVersion":"https://github.com/algorandfoundation/specs/tree/ac2255d586c4474d4ebcf3809acccb59b7ef34ff","nextConsensusVersionRound":13666266,"nextConsensusVersionSupported":true,"timeSinceLastRound":588549147,"catchupTime":0,"hasSyncedSinceStartup":false,"stoppedAtUnsupportedRound":false}

The doc example referred to a block outside of the last 1000 blocks.

Can you check the content of ~/n_test1/data_testnet/algod.net is localhost:4001 and that the content of ~/n_test1/data_testnet/algod.token is your token?

If you’re not running a node in sandbox, the port is usually 8080 and not 4001.

Thank you, fabrice.
Interesting, that the port was 43839.

cat ~/n_test1/data_testnet/algod.net
127.0.0.1:43839