Skip to main content

Client Methods

getClient()

Get and initialize the opencord client instance

Params

ParamTypeRequired
debugbooleanoptional

Example

import { getClient } from "@opencord/client";

const oc = getClient({
debug: true,
});

platform

This property represents the current platform on which the Opencord runtime is running.

PropertyValue
platform'web', 'mobile', 'desktop', 'unkonwn'

Example

// Check if the platform is not unknown, indicating that the plugin is currently
// running in the Opencord runtime and has initialized successfully.
if (oc.platform !== "unknown") {
console.log("✅ Opencord client initialized.");
} else {
console.log("❌ Opencord client initialization failed.");
}

version

This property represents the current version of the Opencord runtime.

Example

// Note: The 'version' value is only available within the opencord runtime and will be an empty string outside of it.
// When the opencord version is too low, 'version' will return the default version number 0.0.1.
console.log("Version", oc.version); // 1.2.0

async getCode()

This method retrieves an authorization code for the current user to authenticate with Open APIs. The code is required to access information related to the current user, channel, and server.

Returns

Promise<RPCMessage<AuthInfo>>

interface AuthInfo {
code: string;
address: string; // Current user's wallet address
userId: string;
}

Example

const { code, message, data } = await oc.getCode();

if (code === 200) {
console.log("✅ Authorization code obtained successfully", data);
} else {
console.log("❌ Failed to obtain authorization code", code, message);
}

After receiving the authorization code from the client-side, you may need to send it to your backend server to obtain more user information through Open API. This can include retrieving the user's current channel and server information, verifying user permissions, and sending notifications, among other functionalities.

For more detailed instructions on how to access and utilize the Open API to manage user permissions and retrieve user information, please refer to the Open API documentation.