GetScatter / ScatterWebExtension

Extension that allows you to sign transactions with your private keys securely from within the browser without ever exposing them.
MIT License
367 stars 127 forks source link

Wrong publickey retrieved from getIdentity and fail to call contract with no callback result #135

Closed ghost closed 5 years ago

ghost commented 5 years ago

hi,

I have a local eos node running on http://127.0.0.1:8888/, I have created local account "anorak" and Active and OwnerKey, also created a contract "anorak", was able to interact with the contract with cleos in terminal. I have configured Network, Keys, and Identities in Scatter, for Account I select the localnetwork 127.0.0.1 and select anorak@active.

However when I use Scatter, I have two issues below

  1. scatter.getIdentity pops up the page I can select my anorak@active account, but the public key in callback result is not my activekey or ownerkey. It is a new key I've never seen before (see comments in code). And I notice if I remove chainId from the code, the pop up page will not able to find the account.
  2. Call to any contract method does not produce any result, for example getplayer does not output anything in then or catch.
const network = { 
      blockchain:'eos', 
      host: '127.0.0.1',
      port: 8888,
      chainId:'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f'
    }
    const requiredFields = {
        accounts:[
            network
        ]
    };

    const eosOptions = {}

    await scatter.getIdentity(requiredFields).then((identity) => {

      console.log(identity) 
      // {hash: "993de2baae3fb4e784cf87d42142d5daa076b2c64b0fb7d3b23f0aa35765f6a7", 
      // publicKey: "EOS8BamBmgo4VnDUp2WnrUczq7MH2yEC4fBuKvWGWP7Hy5YSLBBAq", 
      // name: "RandomRobin7078752", kyc: false, 
      // accounts: Array(1)}

      const account = scatter.identity.accounts.find(account => account.blockchain === 'eos')
      console.log(account)
      //{name: "anorak", authority: "active", blockchain: "eos"}

      const eos = scatter.eos( network, Eos, eosOptions, 'http');

      eos.contract('anorak',requiredFields).then(contract => {

        console.log('calling contract')

        contract.getplayer("anorak").then(trx => {
                console.log(trx)  //  output nothing
            }).catch(e => {
                console.log(e); //  output nothing
            })
        });
    })

Does anyone know if this is an issue with Scatter?

ghost commented 5 years ago

Ok I think I figure out why.

Contract method need await keyword as well as authorisation details from account object , also add async to getIdentify callback, or I will get "await is reserved keyword" when calling contract method.

await scatter.getIdentity(requiredFields).then(async (identity) => {
....
});
 await contract.update('anorak',9,10,50,{ authorization: `${account.name}@${account.authority}`}).then(trx => {
            console.log(trx)  
        }).catch(e => {
            console.log(e); 
        })
      });

so after this fix, I am able to see tx confirmation screen with all the payload data.

Closing this issue now