iost-official / iost.js

41 stars 21 forks source link

test.js:20 Uncaught (in promise) ReferenceError: IOST is not defined #25

Open garry191091 opened 4 years ago

garry191091 commented 4 years ago

How can I resolve this issue?

test.js:20 Uncaught (in promise) ReferenceError: IOST is not defined

nujabes403 commented 4 years ago

You should import IOST library like below:

const IOST = require('iost')

or

import IOST from 'iost'
garry191091 commented 4 years ago

I have added the import IOST from 'iost'. it displays the error test.js:1 Uncaught SyntaxError: Cannot use import statement outside a module.

nujabes403 commented 4 years ago

@garry191091 Could you share your code?

garry191091 commented 4 years ago

`import IOST from iost ; (function() {

var transfer;

document.addEventListener("DOMContentLoaded", async function(event) {
  await new Promise(done => setTimeout(() => done(), 500));

  IWalletJS.enable().then(function(account) {
    if(!account) return;

    const iost = IWalletJS.newIOST(IOST);

    transfer = function() {

      const tx = iost.callABI("token.iost", "transfer", ["iost", account, '2JPTB3X9ePHuKcWKZFCENUtsR4TRqnD1bBq6a45e4cAXhQodMAcqJghbrYUKgktUErUE434vZVrXiu9oMhJrKdnq', "10", "dapp test memo"]);
      tx.addApprove("iost", "10");

      console.log(tx.getApproveList());
      iost.signAndSend(tx)
        .on('pending', function(txid) {
          log("txid: " + txid);

        })
        .on('success', function(result) {
          log("res: " + JSON.stringify(result));

        })
        .on('failed', function(failed) {
          log("failed: " + JSON.stringify(failed));

        })
    }
  })
})

})();

`

nujabes403 commented 4 years ago

How about using const IOST = require('iost') instead?

garry191091 commented 4 years ago

Yes, I have added this but this is the new error now. Uncaught Error: Module name "iost" has not been loaded yet for context: _. Use require([])

Also, previously in my above code. It checks iost enables if it is unlocked or locked. IWalletJS.enable().then(function(account) but it is giving the error of Uncaught (in promise) ReferenceError: IOST is not defined.

What can be missing?

garry191091 commented 4 years ago

here is the error.

https://ibb.co/k54VGFr

nujabes403 commented 4 years ago

Could you share the code importing test.js?

garry191091 commented 4 years ago

` function transfer(){

    alert('no') ;

    IWalletJS.enable().then(function(account) {

    if(!account) return;  

        const IOST = require('iost')    ;

        alert('yes') ;
    })

}

`

garry191091 commented 4 years ago

On adding const IOST = require('iost') I get this error Uncaught (in promise) Error: Module name "iost" has not been loaded yet for context: _. Use require([])