Hey folks,
When I try to create a Moralis Stream I get the following error:
error: MoralisError [Moralis SDK Core Error]: [C0008] Default instance of Core is not set
Maybe important to notice: I can use other API Endpoints like âgetAllStreamsâ or âgetNFTOwnersâ etc., but when trying to call âgetStreamHistoryâ or âMoralis.Streams.addâ it throws the error mentioned above.
Moralis SDK Version:
"moralis": "^2.21.0",
"@moralisweb3/common-evm-utils": "^2.14.3",
async function getOrCreateStream(tag) {
// Get all streams
const allStreams = await Moralis.Streams.getAll({
limit: 100,
});
// Find a stream with the tag
let stream = allStreams.result.find(stream => stream.tag === tag);
if (!stream) {
stream = await Moralis.Streams.add({
tag,
description: "Stream",
chains: [EvmChain.ETHEREUM],
webhookUrl: env.MORALIS_SERVER_SYNC_WEBHOOK_URL,
includeNativeTxs: false
});
await Moralis.Streams.setSettings({
region: "eu-central-1",
});
console.log(stream);
}
if (stream.webhookUrl !== env.MORALIS_SERVER_SYNC_WEBHOOK_URL) {
await Moralis.Streams.update({
id: stream.id,
webhook: env.MORALIS_SERVER_SYNC_WEBHOOK_URL,
});
}
return stream;
}
async function startServer() {
const app = express();
app.use(bodyParser.json());
app.post('/moralis-webhook', (req, res) => {
console.log('Received Moralis event:', req.body);
// Send a response back to Moralis
res.status(200).send({ message: 'Event received' });
});
app.listen(env.MORALIS_SERVER_WEBHOOK_PORT, () => {
console.log(`Moralis Webhook-Server running on port ${env.MORALIS_SERVER_WEBHOOK_PORT}`);
});
return app;
}
async function initMoralisStream(initStream) {
if (!initStream) {
return;
}
// Init Moralis
await Moralis.start({
apiKey: env.moralisApiKey,
});
// Start server
await startServer();
const stream = await getOrCreateStream(env.MORALIS_STREAM_TAG);
console.log(stream);
}