this.$moralis.Plugins.yourPlugin.yourFunction()
This should work
this.$moralis.Plugins.yourPlugin.yourFunction()
This should work
Many thanks. should this be initialised in plugins/moralis.js or on the view page
initialize Moralis in your plugins file and inject it
i have initialized and injected
import Moralis from 'moralis';
Moralis.initialize("key");
Moralis.serverURL = 'server url'
export default ({ app }, inject) => {
inject('moralis', Moralis)
}
called the function
this.$moralis.Plugins.oneInch.getSupportedTokens({chain: 'bsc'})
but get this error âTypeError: Cannot read property âoneInchâ of undefinedâ
You are still initialising your server the wrong way. Check what Ive written earlier
const serverUrl = "https://xxxxx/server";
const appId = "YOUR_APP_ID";
Moralis.start({ serverUrl, appId });
You cannot use Moralis.initialize and Moralis.ServerUrl anymore
You may have to update your Moralis SDK version if this initialization works for you
here is my update init plugin
import Moralis from 'moralis';
const serverUrl = "server url";
const appId = "server key";
Moralis.start({ serverUrl, appId });
export default ({ app }, inject) => {
inject('moralis', Moralis)
}
here is my function implemation
this.$moralis.Plugins.oneInch.getSupportedTokens({chain: 'bsc'})
this is the rsponse" Cannot read properties of undefined (reading âoneInchâ)"
is there something am missing
ok will try updating the version now
If still not working you could add a wait before Moralis.start({ serverUrl, appId });
implemented initialization in template view
<script>
import Moralis from 'moralis';
// Moralis.initialize("r06gMGKTitJyVLjTK2nqF1TEko76I945jwefjrmn");
// Moralis.serverURL = 'ttps://dpb8bevmk2m2.grandmoralis.com:2053/server'
const serverUrl = "https://njpshwmax94s.bigmoralis.com:2053/server";
const appId = "BplBDQh82rS9EOwOWdj2vDlhkoL043l8bsSU0jwc";
Moralis.start({ serverUrl, appId });
export default {
data(){
return {
address:''
}
},
created(){
Moralis.Plugins.oneInch.getSupportedTokens({chain: 'bsc'})
},
methods:{
},
}
}
</script>
response " Cannot read properties of undefined (reading âoneInchâ)"
when call the 1inch plugin with this method
this.$moralis.Web3.oneInch.getSupportedTokens({chain: 'bsc'}).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
it returns âTypeError: Cannot read property âgetSupportedTokensâ of undefinedâ
Moralis.start also runs at the end await this.initPlugins(plugins);
, but if you donât use wait for Moralis.start then if you check plugins before they got initialised then it may not work.
this implementation works perfectly well
this.$moralis.Web3.authenticate().then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
which means moralise is initialising properly
there are multiple things that happen in Moralis.start, not all finish instantly: https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/d02580ffaa6706182af0d4489f6e8faf9ede9b08/src/Parse.js#L34-L46
ok please can you point me to how i can add await to moralis.start function
https://docs.moralis.io/moralis-server/getting-started/quick-start#initialize-moralis
Plugins module loads asynchronously. It is recommended to initialize Moralis with await to make sure plugins are loaded before using them: await Moralis.start({ serverUrl, appId });
link displays page not found. can u check link. could you drop code snippet for adding await to maralise.start function
ok, that link worked few minutes ago for me, now doesnât work for me either, it looks like the interface got updated
instead of Moralis.start({ serverUrl, appId })
you write await Moralis.start({ serverUrl, appId });
Thanks guys for your assistance, @cryptokid was right regarding using await. i was able to solve the issue using the implementation below
async created(){
await Moralis.Plugins.oneInch.getSupportedTokens({chain: 'bsc'})
.then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
},