Skip to content

Instantly share code, notes, and snippets.

@nuevoalex
Created October 8, 2019 22:03
Show Gist options
  • Save nuevoalex/a5432cd821223f5509241aad243206f8 to your computer and use it in GitHub Desktop.
Save nuevoalex/a5432cd821223f5509241aad243206f8 to your computer and use it in GitHub Desktop.
in3
import In3Client from 'in3';
import { ABI } from 'in3/js/src/modules/eth/api';
declare global {
interface Window { test: any; }
}
window.test = window.test || {};
// use the In3Client
const in3 = new In3Client({
proof : 'standard',
signatureCount: 1,
requestCount : 2,
chainId : 'mainnet'
});
// use the ABI-String of the smart contract
const abi = [{"anonymous":false,"inputs":[{"indexed":false,"name":"name","type":"string"},{"indexed":true,"name":"label","type":"bytes32"},{"indexed":true,"name":"owner","type":"address"},{"indexed":false,"name":"cost","type":"uint256"},{"indexed":false,"name":"expires","type":"uint256"}],"name":"NameRegistered","type":"event"}];
// create a contract-object for a given address
const contract = in3.eth.contractAt(abi as ABI[], '0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455') // ENS contract.
window.test.in3 = in3;
window.test.contract = contract;
// Below returns empty correctly
// const logPromise = test.contract.events.NameRegistered.getLogs({fromBlock: 8703826, toBlock: 8703827})
// This produces errors but should respond with a single event
// const logPromise = test.contract.events.NameRegistered.getLogs({fromBlock: 8703825, toBlock: 8703826})
/*
Access to XMLHttpRequest at 'https://www.google.com/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:172 HEAD https://www.google.com/ net::ERR_FAILED
dispatchXhrRequest @ xhr.js:172
xhrAdapter @ xhr.js:11
dispatchRequest @ dispatchRequest.js:59
Promise.then (async)
request @ Axios.js:53
Axios.<computed> @ Axios.js:68
wrap @ bind.js:9
isOnline @ transport.js:54
(anonymous) @ Client.js:435
Promise.then (async)
(anonymous) @ Client.js:435
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
handleRequest @ Client.js:368
(anonymous) @ Client.js:279
(anonymous) @ Client.js:279
fulfilled @ Client.js:37
Promise.then (async)
step @ Client.js:39
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
sendIntern @ Client.js:253
send @ Client.js:208
(anonymous) @ Client.js:186
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
sendRPC @ Client.js:185
send @ api.js:53
getLogs @ api.js:161
getLogs @ api.js:363
(anonymous) @ VM1518:1
index.html:1 Access to XMLHttpRequest at 'https://www.google.com/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:172 HEAD https://www.google.com/ net::ERR_FAILED
dispatchXhrRequest @ xhr.js:172
xhrAdapter @ xhr.js:11
dispatchRequest @ dispatchRequest.js:59
Promise.then (async)
request @ Axios.js:53
Axios.<computed> @ Axios.js:68
wrap @ bind.js:9
isOnline @ transport.js:54
(anonymous) @ Client.js:435
Promise.then (async)
(anonymous) @ Client.js:435
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
handleRequest @ Client.js:368
(anonymous) @ Client.js:279
(anonymous) @ Client.js:279
fulfilled @ Client.js:37
Promise.then (async)
step @ Client.js:39
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
sendIntern @ Client.js:253
send @ Client.js:208
(anonymous) @ Client.js:186
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
sendRPC @ Client.js:185
send @ api.js:53
getLogs @ api.js:161
getLogs @ api.js:363
(anonymous) @ VM1518:1
index.html:1 Access to XMLHttpRequest at 'https://www.google.com/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:172 HEAD https://www.google.com/ net::ERR_FAILED
dispatchXhrRequest @ xhr.js:172
xhrAdapter @ xhr.js:11
dispatchRequest @ dispatchRequest.js:59
Promise.then (async)
request @ Axios.js:53
Axios.<computed> @ Axios.js:68
wrap @ bind.js:9
isOnline @ transport.js:54
(anonymous) @ Client.js:514
rejected @ Client.js:38
Promise.then (async)
step @ Client.js:39
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
handleRequest @ Client.js:368
(anonymous) @ Client.js:279
(anonymous) @ Client.js:279
fulfilled @ Client.js:37
Promise.then (async)
step @ Client.js:39
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
sendIntern @ Client.js:253
send @ Client.js:208
(anonymous) @ Client.js:186
(anonymous) @ Client.js:40
__awaiter @ Client.js:36
sendRPC @ Client.js:185
send @ api.js:53
getLogs @ api.js:161
getLogs @ api.js:363
(anonymous) @ VM1518:1
Client.js:515 Uncaught (in promise) Error: Currently there is no online-connection!
at eval (Client.js:515)
at Generator.next (<anonymous>)
at fulfilled (Client.js:37)
(anonymous) @ Client.js:515
fulfilled @ Client.js:37
Promise.then (async)
getLogs @ api.js:369
(anonymous) @ VM1518:1
index.html:1 Access to XMLHttpRequest at 'https://www.google.com/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:172 HEAD https://www.google.com/ net::ERR_FAILED
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment