Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
garry191091 opened this issue Nov 1, 2019 · 10 comments
Open

Comments

@garry191091
Copy link

How can I resolve this issue?

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

@nujabes403
Copy link
Contributor

You should import IOST library like below:

const IOST = require('iost')

or

import IOST from 'iost'

@garry191091
Copy link
Author

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
Copy link
Contributor

@garry191091 Could you share your code?

@garry191091
Copy link
Author

garry191091 commented Nov 1, 2019

`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
Copy link
Contributor

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

@garry191091
Copy link
Author

garry191091 commented Nov 2, 2019

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
Copy link
Author

here is the error.

https://ibb.co/k54VGFr

@nujabes403
Copy link
Contributor

Could you share the code importing test.js?

@garry191091
Copy link
Author

` function transfer(){

	alert('no') ;
 
	IWalletJS.enable().then(function(account) {
	
	if(!account) return;  
		
		const IOST = require('iost')	;
		
		
		
		alert('yes') ;
	})
	
}

`

@garry191091
Copy link
Author

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([])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants