Skip to content

Instantly share code, notes, and snippets.

@TrillCyborg
Created October 20, 2018 16:32
Show Gist options
  • Save TrillCyborg/d5c04440c4151eff7e3eaf0782871f2d to your computer and use it in GitHub Desktop.
Save TrillCyborg/d5c04440c4151eff7e3eaf0782871f2d to your computer and use it in GitHub Desktop.
Scatter EOS Login
import ScatterJS from 'scatterjs-core'
import ScatterEOS from 'scatterjs-plugin-eosjs'
import EOS from 'eosjs'
const isDev = process.env.NODE_ENV === 'development'
const APP_NAME = 'Test App'
const NETWORK = {
protocol: "http",
blockchain: "eos",
host: "127.0.0.1",
port: 8888,
chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
}
ScatterJS.plugins(new ScatterEOS());
export const initScatter = () => ScatterJS.scatter.connect(APP_NAME).then(async (connected: any) => {
// User does not have Scatter Desktop, Mobile or Classic installed.
if(!connected) {
throw Error('Scatter not connected');
}
try {
const requiredFields = { accounts: [ NETWORK ] };
const scatter = ScatterJS.scatter
const eos: any = scatter.eos(NETWORK, EOS, {}, NETWORK.protocol);
const identity = await scatter.getIdentity(requiredFields)
const account = identity.accounts.find((a: any) => a.blockchain === 'eos');
// Save to application store
// save({ scatter, eos, identity, account })
if (isDev) {
(window as any).Scatter = scatter
(window as any).EOS = eos
(window as any).EOSIdentity = identity
(window as any).EOSAccount = account
}
} catch (e) {
console.error(e, "Identity Crisis!")
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment