Closed emr closed 2 years ago
The types have been updated and should be correct now. You were correct that providing an object with apiKey and serverUrl is the right way.
In fact, you should not have to use Moralis.Web3API.initialize
manually. You can call Moralis.start
which will initialize everything for you (setting serverUrl and appId as well for example).
If you want to use Moralis.start in a NodeJs environment, then you can use the moralisSecret
(instead of manually providing the apiKey, this will also initialize web3 via the speedy-nodes). You can find this moralisSecret when you login to Moralis > account-settings > API. When you initialize moralis with this secret, then you can use the web3Api, and you don't even have to provide the serverUrl (but then you will have limited features, ex. no access to database functionalities)
We will add it to the documentation. You're right that we have not updated it there as it has just been released.
If you have more questions, please reach out to our forums, as the support team is more active over there :)
Issue Description
I want to send requests to Moralis Web3Api from my nodejs application. For doing this, I use
Moralis.Web3API
.First, I call
Moralis.Web3API.initialize
and then what I want to call from the API. It works but there is a type incompatibility forinitialize
method ofWeb3Api
class.Code
In the source code, the method expects an object with
serverUrl
andapiKey
props. https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/main/src/MoralisWeb3Api.js#L13But in the generated type, the method expects only a string that will be used as server URL. https://github.com/MoralisWeb3/Moralis-JS-SDK/blob/main/types/generated/web3Api.d.ts#L1869
Result
If I want to call the method as above as declared in the type file, naturally, I get this error:
Actually, I haven't seen anything about initializing Moralis and sending API calls through the SDK with nodejs in documentations. So I tried to use SDK in this way. Am I using SDK in the wrong way? So what should I do? How can I use the SDK in nodejs properly?
Thank you all!