Provider

open class Provider

The core class for interacting with the Portal API and managing user accounts. Provides blockchain interaction capabilities, handling authentication, event-driven communication, and transaction signing.

This class provides functionalities for:

  • Making API requests.

  • Handling events and event listeners.

  • Managing user accounts and addresses.

  • Signing requests.

  • Interacting with the Portal MPC network.

  • Handling connection events.

Parameters

apiKey

The API key for authenticating with the Portal API.

keychain

The storage adapter for managing sensitive data, such as user addresses.

rpcConfig

A map of chain IDs to RPC URLs, used for interacting with different blockchain networks.

autoApprove

(Optional) If true, requests are automatically approved without user interaction. Defaults to false.

featureFlags

(Optional) A set of feature flags to enable or disable specific functionalities. Defaults to null.

version

(Optional) The API version to use. Defaults to "v6".

apiHost

(Optional) The base URL of the Portal API. Defaults to "api.portalhq.io".

mpcHost

(Optional) The base URL of the Portal MPC network. Defaults to "mpc.portalhq.io".

requests

(Optional) An instance of PortalRequests for making HTTP requests. Defaults to a new PortalRequests instance.

Constructors

Link copied to clipboard
constructor(apiKey: String, keychain: MobileStorageAdapter, rpcConfig: Map<String, String>, autoApprove: Boolean = false, featureFlags: FeatureFlags? = null, version: String = "v6", apiHost: String = "api.portalhq.io", mpcHost: String = "mpc.portalhq.io", requests: PortalRequests = PortalRequests())

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

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

Emits an event and triggers all registered handlers for that event.

Link copied to clipboard
suspend fun getAddress(namespace: PortalNamespace): String?

Retrieves the address associated with a specific blockchain namespace.

suspend fun getAddress(chainId: String): String?

Retrieves the address associated with a specific blockchain chain ID.

Link copied to clipboard

Retrieves the RPC URL for a given blockchain chain ID.

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

Registers an event listener for a specific event.

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

Registers a one-time event listener for a specific event.

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

Removes an event listener for a given event.

Link copied to clipboard
open suspend fun request(chainId: String, method: PortalRequestMethod, params: List<Any>, connect: PortalConnect? = null): PortalProviderResult

Sends a request to the Portal provider.

Link copied to clipboard
fun updateChain(newChainId: String, connect: PortalConnect? = null)

Updates the blockchain chain ID and emits a chain change event.