unable to get past the auth in balance.ts #25
Unanswered
Arpit-R-Doshi
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I would recommend u to use yellow sdk |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
// src/authAndBalance.ts
import WebSocket from 'ws';
import { Wallet } from 'ethers';
// --- Helper function to create a signed payload (no changes here) ---
async function createSignedPayload(wallet: Wallet, method: string, params: any[] | object) {
const requestId = Date.now();
const nonce = Date.now() - Math.floor(Math.random() * 1000);
const req = [requestId, method, params, nonce];
const messageToSign = JSON.stringify(req);
const signature = await wallet.signMessage(messageToSign);
return {
req,
sig: [signature],
};
}
// --- Main Function ---
export async function authenticateAndGetBalance(
wsUrl: string,
sessionKey: { address: string; privateKey: string }
): Promise<any[]> {
const wallet = new Wallet(sessionKey.privateKey);
const ws = new WebSocket(wsUrl);
}
// --- Example Usage (no changes here) ---
const sessionKey = {
address: '0xfC6e3552507144066e190a371648f6FF734bb4b0',
privateKey: '0xc4c317d0860d15e98aacb3fc1c1141b3fa1559009208938678de252934319f8e'
};
const wsUrl = 'wss://clearnet-sandbox.yellow.com/ws';
authenticateAndGetBalance(wsUrl, sessionKey)
.then(balances => {
console.log('\n--- Wallet Balances ---');
if (balances.length === 0) {
console.log('Authentication successful, but no funds found for this address.');
console.log('The next step is to use a Faucet to fund this address.');
} else {
balances.forEach(balance => {
console.log(
Asset: ${balance.asset}, Amount: ${balance.amount}
);});
}
console.log('-----------------------\n');
})
.catch(err => {
console.error('\n--- SCRIPT FAILED ---');
console.error(err);
console.log('---------------------\n');
});
C:\Users\Arpit Doshi\nitrolite-transfer\backend>npx tsx src/balance.ts
Sending auth_request: {
"req": [
1758738337671,
"auth_request",
[
{
"address": "0xfc6e3552507144066e190a371648f6ff734bb4b0"
}
],
1758738336840
],
"sig": [
"0x111ff220d1fa9a73ea7461d01c597ca6b5907ba48674d5f9c83158ee966c6bfb315e175a8f3ced01b7e85d4c6568acde03d4f5bda6a60442df57d96c9fdad54a1b"
]
}
Error message received from server: {
"res": [
1758738337671,
"error",
{
"error": "failed to parse auth parameters"
},
1758738341186
],
"sig": [
"0xd824ae4a2f88c76dec8f1a44d5604928580ec95336899bc9340e8c0b0e3fc16c15e1498bbd27d5828f01f80ed188e607e8a6673a0725d7aa630f81c24f3971211c"
]
}
--- SCRIPT FAILED ---
Request failed: failed to parse auth parameters
WebSocket connection closed.
Beta Was this translation helpful? Give feedback.
All reactions