Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 89f2217

Browse files
committed
Refactor accountExists function to include error handling and ensure consistent return values
1 parent 8aba022 commit 89f2217

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

packages/rpc/src/methods/account.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ import { AccountParams } from '../types';
22
import { callNearRpc } from '../util';
33

44
export const accountExists = async ({ accountId, rpcUrl }: AccountParams): Promise<boolean> => {
5+
try {
6+
const res = await callNearRpc({
7+
params: {
8+
request_type: 'view_account',
9+
finality: 'final',
10+
account_id: accountId,
11+
},
12+
method: 'query',
13+
rpcUrl });
514

6-
const res = await callNearRpc({
7-
params: {
8-
request_type: 'view_account',
9-
finality: 'final',
10-
account_id: accountId,
11-
},
12-
method: 'query',
13-
rpcUrl });
14-
15-
if (res?.error) {
16-
return false;
15+
if (res?.error) {
16+
return false;
17+
}
18+
return true;
19+
} catch (error) {
20+
return true;
1721
}
18-
return true;
1922
};

0 commit comments

Comments
 (0)