MoralisWeb3 / Moralis-JS-SDK

Moralis Official Javascript SDK
https://docs.moralis.io
Other
368 stars 257 forks source link

bug: SDK Core Error: [C0013] Key "apiKey" is unregistered. Have you registered all required modules? #1218

Closed mburger81 closed 2 months ago

mburger81 commented 3 months ago

New Bug Report

Checklist

Issue Description

Using moralis sdk instead of the Moralis monolith to fetch nfts for wallet I get the error "apiKey" is unregistered.

Steps + code to reproduce

This code snipped for Moralis SDK doesnt work

const core = Core.create();
// Register all imported modules to the @moralisweb3/common-core module
this.evmApi = EvmApi.create(core);
core.registerModules([this.evmApi]);
await core.start({

  apiKey: MORALIS_API_KEY,
});

fetchNfts(address: string): Promise<Array<any>> {
    return new Promise(async (resolve, reject) => {
        await this.init();
        var ret = [];
        const chains = ["0x64", "0x27d8"];

        for(const chain of chains) {
          const options: any = {
            "chain": chain,
            "format": "decimal",
            "mediaItems": true,
            "address": address
          }
          const response = await this.evmApi?.nft.getWalletNFTs(options);
          console.log('##### response', response);

          ret = ret.concat(response.raw.result);
        }

        resolve(ret);
      })
  }

but using the monolith works fine with the expected output

await Moralis.start({
  apiKey: MORALIS_API_KEY,
});
// same code for fetchNfts but using Monolith Moralis import
const response = await Moralis.EvmApi.nft.getWalletNFTs(options);

I think he first part of this forum request is raising up the same type of issue https://forum.moralis.io/t/moralis-sdk-installed-from-parts-packages-errors/20353/2

Actual Outcome

Using sdk instead of monolith is running into an issue bug: SDK Core Error: [C0013] Key "apiKey" is unregistered. Have you registered all required modules?

In my opinion we are doing exactly how described from the documentation

Expected Outcome

It should work, or if we do something wrong maybe you should adapt your documentation as well

Client

Logs

Moralis SDK Core Error: [C0013] Key "apiKey" is unregistered. Have you registered all required modules?
    at Config.getItem (http://localhost:8100/vendor.js:377601:13)
    at Config.get (http://localhost:8100/vendor.js:377570:17)
    at OperationRequestBuilder.prepareHeaders (http://localhost:8100/vendor.js:376496:35)
    at PaginatedOperationResolver.<anonymous> (http://localhost:8100/vendor.js:376659:46)
    at step (http://localhost:8100/vendor.js:376428:17)
    at Object.next (http://localhost:8100/vendor.js:376377:14)
    at http://localhost:8100/vendor.js:376351:67
    at new ZoneAwarePromise (http://localhost:8100/polyfills.js:11416:21)
    at __awaiter (http://localhost:8100/vendor.js:376333:10)
    at PaginatedOperationResolver.fetch (http://localhost:8100/vendor.js:376646:14)
mburger81 commented 3 months ago

I've seen the issue is happening at

await core.start({
  apiKey: MORALIS_API_KEY,
});

So it doesn't even matter the nft.getWalletNFTs call, its already failing initialising the modules.

In my opinion also the documentation from here https://docs.moralis.io/web3-data-api/advanced-sdk-setup and what I see in the README.MD file of this project is not exactly the same. So its a little bit confusing, what is the right way to go for using the advanced sdk mode.

The documentation is talking about using @moralisweb3/core and the readme is talking about @moralisweb3/common-core but both examples are not working.

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. for your contributions. If this issue is still affecting you, please leave any comment, and we'll keep it open We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! Thank you.

stale[bot] commented 2 months ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

DevHusariaSolutions commented 1 month ago

Probably it will solve issue https://github.com/MoralisWeb3/docs/pull/476