Hey so I updated my code and now it looks like this:
await Moralis.start({
apiKey: process.env.MORALIS_API_KEY,
});
const results: EvmNft[] = [];
let response;
try {
response = await Moralis.EvmApi.token.getNFTOwners({
address: '0x99903e8eC87b9987bD6289DF8eff178d6E533561',
chain: EvmChain.ETHEREUM,
});
results.push(...response.result);
} catch (err) {
console.log(err);
}
let iterations = 0;
while (response && response.hasNext()) {
if (iterations === 100) {
break;
}
try {
const nextResponse = await response.next();
results.push(...nextResponse.result);
console.log(results.length);
response = nextResponse;
iterations += 1;
} catch (err) {
console.log(err);
if (iterations === 0) {
break;
}
}
}
It runs every ten minutes and if there is no errors while loop runs 22 times as the collection I’m checking consists of 2137 NFTs. I also added the mechanism that the loop will break if there were 100 iterations (of errors) and then it waits patiently for another cron job. But once the errors start coming there is no turning back for some reason and the only thing that works is stopping the app for some time and then restarting it again.
The error I’m logging is
MoralisError [Moralis SDK Core Error]: [C0006] Request failed with status 400: Request failed with status code 400
at RequestController.makeError (/usr/src/app/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:137:20)
at RequestController.<anonymous> (/usr/src/app/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:118:38)
at step (/usr/src/app/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:44:23)
at Object.throw (/usr/src/app/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:25:53)
at rejected (/usr/src/app/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:17:65)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
isMoralisError: true,
code: 'C0006',
details: {
status: 400,
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /api/v2/nft/0x99903e8eC87b9987bD6289DF8eff178d6E533561/owners?chain=0x1&cursor=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsidG9rZW5BZGRyZXNzIjoiMHg5OTkwM2U4ZWM4N2I5OTg3YmQ2Mjg5ZGY4ZWZmMTc4ZDZlNTMzNTYxIn0sImtleXMiOlsiMTY2MTI1OTE5Ny4zNDMiLCIxNjYxNzY3NTQ0LjUyMSIsIjE2NjE4NjM4MjAuMTY5IiwiMTY2MjA1NDU1OC41NDMiLCIxNjYyMzU1NDAwLjAwOCIsIjE2NjMwMTgwMzcuMDY2Il0sIndoZXJlIjp7InRva2VuX2FkZHJlc3MiOiIweDk5OTAzZThlYzg3Yjk5ODdiZDYyODlkZjhlZmYxNzhkNmU1MzM1NjEifSwibGltaXQiOjEwMCwib2Zmc2V0IjowLCJvcmRlciI6W10sInRvdGFsIjoyMTM3LCJwYWdlIjo2LCJ0YWlsT2Zmc2V0IjoxLCJpYXQiOjE2NjM2OTkyMDB9.bG-aYMZuEdlJTeMpa9aMZEUEiZ-JmJ6M1bBvIhhGO-k&offset=4000 HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'x-api-key: 423535\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Host: deep-index.moralis.io\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/v2/nft/0x99903e8eC87b9987bD6289DF8eff178d6E533561/owners?chain=0x1&cursor=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsidG9rZW5BZGRyZXNzIjoiMHg5OTkwM2U4ZWM4N2I5OTg3YmQ2Mjg5ZGY4ZWZmMTc4ZDZlNTMzNTYxIn0sImtleXMiOlsiMTY2MTI1OTE5Ny4zNDMiLCIxNjYxNzY3NTQ0LjUyMSIsIjE2NjE4NjM4MjAuMTY5IiwiMTY2MjA1NDU1OC41NDMiLCIxNjYyMzU1NDAwLjAwOCIsIjE2NjMwMTgwMzcuMDY2Il0sIndoZXJlIjp7InRva2VuX2FkZHJlc3MiOiIweDk5OTAzZThlYzg3Yjk5ODdiZDYyODlkZjhlZmYxNzhkNmU1MzM1NjEifSwibGltaXQiOjEwMCwib2Zmc2V0IjowLCJvcmRlciI6W10sInRvdGFsIjoyMTM3LCJwYWdlIjo2LCJ0YWlsT2Zmc2V0IjoxLCJpYXQiOjE2NjM2OTkyMDB9.bG-aYMZuEdlJTeMpa9aMZEUEiZ-JmJ6M1bBvIhhGO-k&offset=4000',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'deep-index.moralis.io',
protocol: 'https:',
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(kUniqueHeaders)]: null
},
response: {
status: 400,
statusText: 'Bad Request',
headers: [Object],
config: [Object],
request: [ClientRequest],
data: [Object]
}
},
[cause]: [AxiosError: Request failed with status code 400] {
code: 'ERR_BAD_REQUEST',
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 10000,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object],
url: 'https://deep-index.moralis.io/api/v2/nft/0x99903e8eC87b9987bD6289DF8eff178d6E533561/owners',
params: [Object],
method: 'get',
data: undefined
},
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /api/v2/nft/0x99903e8eC87b9987bD6289DF8eff178d6E533561/owners?chain=0x1&cursor=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsidG9rZW5BZGRyZXNzIjoiMHg5OTkwM2U4ZWM4N2I5OTg3YmQ2Mjg5ZGY4ZWZmMTc4ZDZlNTMzNTYxIn0sImtleXMiOlsiMTY2MTI1OTE5Ny4zNDMiLCIxNjYxNzY3NTQ0LjUyMSIsIjE2NjE4NjM4MjAuMTY5IiwiMTY2MjA1NDU1OC41NDMiLCIxNjYyMzU1NDAwLjAwOCIsIjE2NjMwMTgwMzcuMDY2Il0sIndoZXJlIjp7InRva2VuX2FkZHJlc3MiOiIweDk5OTAzZThlYzg3Yjk5ODdiZDYyODlkZjhlZmYxNzhkNmU1MzM1NjEifSwibGltaXQiOjEwMCwib2Zmc2V0IjowLCJvcmRlciI6W10sInRvdGFsIjoyMTM3LCJwYWdlIjo2LCJ0YWlsT2Zmc2V0IjoxLCJpYXQiOjE2NjM2OTkyMDB9.bG-aYMZuEdlJTeMpa9aMZEUEiZ-JmJ6M1bBvIhhGO-k&offset=4000 HTTP/1.1\r\n' +
'Accept: application/json, text/plain, */*\r\n' +
'x-api-key: 32423424\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Host: deep-index.moralis.io\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/api/v2/nft/0x99903e8eC87b9987bD6289DF8eff178d6E533561/owners?chain=0x1&cursor=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsidG9rZW5BZGRyZXNzIjoiMHg5OTkwM2U4ZWM4N2I5OTg3YmQ2Mjg5ZGY4ZWZmMTc4ZDZlNTMzNTYxIn0sImtleXMiOlsiMTY2MTI1OTE5Ny4zNDMiLCIxNjYxNzY3NTQ0LjUyMSIsIjE2NjE4NjM4MjAuMTY5IiwiMTY2MjA1NDU1OC41NDMiLCIxNjYyMzU1NDAwLjAwOCIsIjE2NjMwMTgwMzcuMDY2Il0sIndoZXJlIjp7InRva2VuX2FkZHJlc3MiOiIweDk5OTAzZThlYzg3Yjk5ODdiZDYyODlkZjhlZmYxNzhkNmU1MzM1NjEifSwibGltaXQiOjEwMCwib2Zmc2V0IjowLCJvcmRlciI6W10sInRvdGFsIjoyMTM3LCJwYWdlIjo2LCJ0YWlsT2Zmc2V0IjoxLCJpYXQiOjE2NjM2OTkyMDB9.bG-aYMZuEdlJTeMpa9aMZEUEiZ-JmJ6M1bBvIhhGO-k&offset=4000',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'deep-index.moralis.io',
protocol: 'https:',
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(kUniqueHeaders)]: null
},
response: {
status: 400,
statusText: 'Bad Request',
headers: [Object],
config: [Object],
request: [ClientRequest],
data: [Object]
}
}
}
and unfortunately it tells me nothing. I’m using this service in production and it is responsible for really important function in our product’s website (it displays leaderboard of token holders). We are paying for highest subscription tier so is there any way to contact someone support that would help us with the issue?