Skip to content

Instantly share code, notes, and snippets.

@hewigovens
Last active April 8, 2021 07:21
Show Gist options
  • Save hewigovens/c9bcd5c7e1b00532292af8120f45ed4d to your computer and use it in GitHub Desktop.
Save hewigovens/c9bcd5c7e1b00532292af8120f45ed4d to your computer and use it in GitHub Desktop.
Test CORS
var testEndpointCORS = (url) => {
var method = "POST";
var xhr = new XMLHttpRequest();
var json = {
jsonrpc: "2.0",
method: "eth_getBlockByHash",
params: [
"0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35",
true,
],
id: 1,
};
xhr.onload = console.log;
xhr.onerror = console.log;
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(json));
};
@hewigovens
Copy link
Author

How to test:

  1. open web console and paste the code above
  2. testEndpointCORS(<your_eth_endpoint>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment