[SOLVED] V2 Auth API error code 400

I try a demo base on https://github.com/0xMattCarter/web3-login-v2.git.
After connectd wallet,then send requestMessage to backend.

const result = await Moralis.Auth.requestMessage(o);

return this error.

ErrorHandler MoralisError [Moralis SDK Core Error]: [C0006] Request failed with status undefined: read ECONNRESET
at RequestController.makeError (D:\gaa\web3-login-v2\node_modules@moralisweb3\core\src\controllers\RequestController.ts:78:14)
at RequestController. (D:\gaa\web3-login-v2\node_modules@moralisweb3\core\src\controllers\RequestController.ts:61:26)
at step (D:\gaa\web3-login-v2\node_modules@moralisweb3\core\lib\controllers\RequestController.js:44:23)
at Object.throw (D:\gaa\web3-login-v2\node_modules@moralisweb3\core\lib\controllers\RequestController.js:25:53)
at rejected (D:\gaa\web3-login-v2\node_modules@moralisweb3\core\lib\controllers\RequestController.js:17:65)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
isMoralisError: true,
code: ‘C0006’,
details: {…

SDK call url “https://auth-api.do-prod-1.moralis.io/challenge/request/evm” and get 400 error.

Use this latest url https://authapi.moralis.io/challenge/request/evm

And Can you share your request body?

So, how to change or config the URL in SDK v2.4.0?
and this is error log with request data,
cause: AxiosError: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
syscall: ‘read’,
code: ‘ECONNRESET’,
errno: -54,
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://auth-api.do-prod-1.moralis.io/challenge/request/evm’,
params: {},
method: ‘post’,
data: ‘{“chainId”:“0x1”,“address”:“0xE92D8FDE20547332B8C7b34A362aD5eA34edc9bd”,“domain”:“omnimint.xyz”,“statement”:“Please sign this message to confirm your identity.”,“uri”:“https://omnimint.xyz”,“expirationTime”:“2023-01-01T00:00:00.000Z”,“timeout”:15}’
},

If the url is from the sdk, then it is fine.

and seems like you are missing a property. Add network value as evm and use chain property name instead of chainId

Thx for your reply.
Request Code:
let params = {
address,
chain,
network,
domain: DOMAIN,
statement: STATEMENT,
uri: URI,
expirationTime: EXPIRATION_TIME,
timeout: TIMEOUT,
};
console.log(‘params=’,params);
const result = await Moralis.Auth.requestMessage(params);

params log is {
address: ‘0xE92D8FDE20547332B8C7b34A362aD5eA34edc9bd’,
chain: 1,
network: ‘evm’,
domain: ‘omnimint.xyz’,
statement: ‘Please sign this message to confirm your identity.’,
uri: ‘https://omnimint.xyz’,
expirationTime: ‘2023-01-01T00:00:00.000Z’,
timeout: 15
}

the field chainId is generated by SDK.

Is it solved now, after adding the network?

Yes, i log params just now Moralis.Auth.requestMessage(params), params contains network :‘evm’ as you see above.
and the sdk still request URL ‘https://auth-api.do-prod-1.moralis.io/challenge/request/evm’ and got 400 error. Is the url valid? I call this url in browser got 400 too.

The api url is correct. If you are trying from the browser, try this body. It worked for me in the browser.

address: "0xE92D8FDE20547332B8C7b34A362aD5eA34edc9bd",
chainId: 1,
network: "evm",
domain: "omnimint.xyz",
statement: "Please sign this message to confirm your identity.",
uri: "https://omnimint.xyz",
expirationTime: "2023-01-01T00:00:00.000Z",
timeout: 15

If you are trying from the API call from the browser then you can use chainId and in sdk it is defined as chain.

Wow, It works, but the param fied is chain, not chainId in the SDK the DOC (https://docs.moralis.io/docs/authentication) , and the code IN SDK

Blockquote
export interface RequestMessageEvmOptions {
network: ‘evm’;
domain: string;
chain: EvmChainish;
address: EvmAddressish;
statement?: string;
uri: string;
expirationTime?: string;
notBefore?: string;
resources?: string[];
timeout: number;
}

2 Likes