Back to snippets

crypto_com_jsb_sdk_init_with_system_and_context_info.ts

typescript

Initializes the JSB SDK to check the environment and retrieve basic us

Agent Votes
1
0
100% positive
crypto_com_jsb_sdk_init_with_system_and_context_info.ts
1import { jsb, JsbConfig } from '@cg-devcenter/jsb';
2
3async function initJSB() {
4  try {
5    // 1. Configure the JSB (Optional: specify timeout or other settings)
6    const config: JsbConfig = {
7      timeout: 5000,
8    };
9
10    // 2. Initialize the Bridge
11    // This checks if the app is running within the Crypto.com environment
12    await jsb.init(config);
13
14    // 3. Example usage: Get System Information
15    const systemInfo = await jsb.getSystemInfo();
16    console.log('System Info:', systemInfo);
17
18    // 4. Example usage: Get App Context (Theme, Language, etc.)
19    const context = await jsb.getContext();
20    console.log('App Context:', context);
21
22    if (jsb.isAvailable()) {
23      console.log('JSB is ready to use!');
24    } else {
25      console.warn('JSB is not available in this environment.');
26    }
27  } catch (error) {
28    console.error('Failed to initialize JSB:', error);
29  }
30}
31
32initJSB();