1ich plugin error using Nuxtjs

i have been having issues with 1inch plugin on nuxtjs, i keep getting this error message “TypeError: Cannot read property ‘oneinch’ of undefined” below is my code implemation

 this.$moralis.Web3.Plugins.oneInch.getSupportedTokens({chain: 'bsc'}).then(res => {
        console.log(res);
        }).catch(err => {
          console.log(err);

        });

Hi! Did you initiliaze your server properly? If so. Please provide the file where you import moralis in your nuxt plugin folder

plugin/moralis.js

import Moralis from 'moralis';

Moralis.initialize("key");
Moralis.serverURL = 'server url'

export default ({ app }, inject) => {

inject('moralis', Moralis)

}


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

1 Like

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

  1. Make sure your server is updated
  2. Make sure you have the latest moralis package installed
  3. Make sure you have installed Plugins in your server

Install Plugins - Moralis

If still not working you could add a wait before Moralis.start({ serverUrl, appId });

  1. installed new server - check
  2. updated moarlis page "“moralis”: “^0.0.104”
  3. 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