iost.js
iost.js copied to clipboard
test.js:20 Uncaught (in promise) ReferenceError: IOST is not defined
How can I resolve this issue?
test.js:20 Uncaught (in promise) ReferenceError: IOST is not defined
You should import IOST library like below:
const IOST = require('iost')
or
import IOST from 'iost'
I have added the
import IOST from 'iost'
. it displays the error
test.js:1 Uncaught SyntaxError: Cannot use import statement outside a module
.
@garry191091 Could you share your code?
`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));
})
}
})
})
})();
`
How about using const IOST = require('iost')
instead?
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?
here is the error.
https://ibb.co/k54VGFr
Could you share the code importing test.js?
` function transfer(){
alert('no') ;
IWalletJS.enable().then(function(account) {
if(!account) return;
const IOST = require('iost') ;
alert('yes') ;
})
}
`
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([])