PortalConnect

class PortalConnect(apiKey: String, var chainId: Int, keychain: MobileStorageAdapter, gatewayConfig: Map<Int, String>, webSocketServer: String = "connect.portalhq.io", autoApprove: Boolean = false, apiHost: String = "api.portalhq.io", mpcHost: String = "mpc.portalhq.io", version: String = "v6") : EventBus

PortalConnect is the main class for managing connections and interactions with the Portal network. It handles WebSocket communication, session management, and signing requests, providing a high-level interface for applications to integrate with the Portal infrastructure.

This class extends EventBus, enabling it to emit and listen for various events related to the connection and signing processes.

Constructors

Link copied to clipboard
constructor(apiKey: String, chainId: Int, keychain: MobileStorageAdapter, gatewayConfig: Map<Int, String>, webSocketServer: String = "connect.portalhq.io", autoApprove: Boolean = false, apiHost: String = "api.portalhq.io", mpcHost: String = "mpc.portalhq.io", version: String = "v6")

Creates a new PortalConnect instance, initializing the provider and setting up event listeners.

Properties

Link copied to clipboard
Link copied to clipboard

The current chain ID the client is connected to.

Link copied to clipboard

Functions

Link copied to clipboard

Adds new chains to the existing list of chains in a SessionProposal's required namespaces.

Link copied to clipboard
Link copied to clipboard
fun connect(uri: String)

Establishes a connection to the WebSocket server with the given URI.

Link copied to clipboard
fun deinit()

Cleans up event handlers and releases resources.

Link copied to clipboard
fun disconnect(userInitiated: Boolean = false)

Disconnects the WebSocket client.

Link copied to clipboard
fun emit(event: String, data: Any)

Executes all registered event handlers for a given event

Link copied to clipboard
fun emitGetSessionRequest(requestId: String, topic: String)

Emits a "portal_getSessionRequest" event to the connected client.

Link copied to clipboard
fun on(event: String, handler: (data: Any) -> Unit)

Registers an event handler for a given event

Link copied to clipboard
fun once(event: String, handler: (data: Any) -> Unit)

Registers an event handler for a given event

Link copied to clipboard
fun onDestroy()

Sends a final message and disconnects the WebSocket client.

Link copied to clipboard
fun removeEventListener(event: String, handler: (data: Any) -> Unit? = null): Boolean

Unregisters an event handler for a given event

Link copied to clipboard
fun updateChain(newChainId: Int)