GetScatter / scatter-js

Importable JavaScript library that allows web applications to directly interface with Scatter Desktop, Classic and Mobile.
MIT License
262 stars 148 forks source link

TypeError: scatter.eosHook is not a function #40

Closed 86chenjie closed 6 years ago

86chenjie commented 6 years ago

throw error with code:

import ScatterJS from 'scatterjs-core'
import ScatterEOS from 'scatterjs-plugin-eosjs2'
ScatterJS.plugins(new ScatterEOS());

const eosjs = require('eosjs')
const fetch = require('node-fetch')            
const { TextDecoder, TextEncoder } = require('text-encoding')

async login ({commit, state, dispatch}) { 
      const connectionOptions = {initTimeout: 20000}
      const connected = ScatterJS.scatter.connect("xxxx", connectionOptions)
      if (!connected) throw new Error('no-scatter')
      const scatter = ScatterJS.scatter
      const network = {
        blockchain: 'eos',
        protocol: process.env.EOS_PROTOCOL,
        host: process.env.EOS_HOST,
        port: process.env.EOS_PORT,
        chainId: process.env.EOS_CHAINID
      }
      console.log(network)
      const requiredFields = { accounts: [network] }
      await scatter.getIdentity(requiredFields)
      const account = scatter.identity.accounts.find(x => x.blockchain === 'eos')
      const accountName = account.name
      console.log(accountName)
      commit('setScatter', scatter)

      rpc = new eosjs.Rpc.JsonRpc('http://127.0.0.1:8000', { fetch });
      api = new eosjs.Api({ rpc, signatureProvider:scatter.eosHook(network), textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });

      // window.ScatterJS = null

}
nsjames commented 6 years ago

eosHook() will not work with the extension as it doesn't have that capability. use the scatter.eos(network, Eos) instead.

nsjames commented 6 years ago

Oh, also eosjs2 isn't supported by the extension at all.

ghost commented 6 years ago

ETA for eosjs2 support?

nsjames commented 6 years ago

The extension is deprecated, and it's unlikely to get eosjs2 support in the near future until there is a way to combat automatic updating of itself.

Scatter Desktop fully supports eosjs2 though.

ghost commented 6 years ago

@nsjames awesome