warp-contracts / warp

An implementation of the Arweave SmartWeave smart contracts protocol.
MIT License
157 stars 44 forks source link

Inconsistent CORS Error with smartweave.contract.readState() #155

Closed twilson63 closed 2 years ago

twilson63 commented 2 years ago

I am getting an inconsistent CORS error when trying to readState of a SmartWeave Contract, the command works inconsistently and it appears to be a result of a fetch to this CloudFront server - https://d1o5nlqr4okus2.cloudfront.net.

Here is the line of code: https://github.com/redstone-finance/redstone-smartcontracts/blob/6ad33a022527a506cdb7d0011e6bfe25004818ef/src/core/SmartWeaveBuilder.ts#L22

Should this line be pointing to https://gateway.redstone.finance instead of https://d1o5nlqr4okus2.cloudfront.net ?

Could it be that this node is just busy and the https://gateway.redstone.finance domain could balance to multiple nodes? If so, I am happy to submit a PR, if I could be using it wrong, I would be happy to correct it.

Here is my call:

const contract = smartweave.contract(contractId);

async function getVisits() {
  return contract.readState().then((res) => res.state);
}

You can reproduce with this demo app - https://arweave.net/IBmNAx1Q6ZF5JkiJ4bfAou6ehtHk8VPUK_406qQRz5s/

ppedziwiatr commented 2 years ago

Hey, thanks, I'll take a look...we've decided at some point to stop using the gateway.redstone.finance domain - to not be dependant on a centralised domain service (which once have failed us)...anyway, I'll try to verify what is going on, maybe it has sth to do with a cloudfront configuration.

ppedziwiatr commented 2 years ago

note to myself: headers response policy should be set to Managed-CORS-With-Preflight. @twilson63 , I believe the issue has been fixed, can you please verify?

twilson63 commented 2 years ago

Confirmed, it is working! 🙏🏻