I was overseeing something. Plugins is undefined because it does not come from Web3.
It is accessible directly through Moralis. In this case through $moralis
@LocoTheDev can u tell me how to call it. should i exclude plugins like so
```
this.$moralis.Web3.oneInch.getSupportedTokens({chain: ‘bsc’}).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
});
Your server is not initilazed properly.
const serverUrl = "https://xxxxx/server";
const appId = "YOUR_APP_ID";
Moralis.start({ serverUrl, appId });
This is the way you do it nowadays. Make sure to update your Server in the moralis dashboard and to have the latest moralis npm package installed!
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
- Make sure your server is updated
- Make sure you have the latest moralis package installed
- Make sure you have installed Plugins in your server
If still not working you could add a wait before Moralis.start({ serverUrl, appId });
- installed new server - check
- updated moarlis page "“moralis”: “^0.0.104”
- 1inch plugin installed on server - check
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 });