⌨️Connector API
Overview
The Connector API is a new addition to the Altura SDK, which allows DApps to connect to and integrate with wallets easily. Using a connector, the Altura SDK automatically fills in the user's wallet information for certain SDK methods, such as get users.
Connector Interface
Using Connectors
Connectors can optionally be passed into the constructor for the Altura
class. Doing so allows for easier access integration with wallets via the Altura SDK.
Default Connectors
By default, the Altura SDK provides two implementations for connectors:
First-party support for more common wallets may be added in the future.
Writing Custom Connectors
To make a wallet compatible with the connector API, it needs a connector that follows the IConnector
interface.
The IConnector
interface contains two functions and two fields:
connect: () => Promise<string | null>
connect: () => Promise<string | null>
This function should connect the wallet to the application, usually prompting the user in the process, returning either the wallet address or null
representing a failed state. This function is invoked in the constructor of the Altura
class.
sign: (message: string) => Promise<string | null>
sign: (message: string) => Promise<string | null>
This function should have the wallet sign an arbitrary message, returning either the signed message or null
representing a failed state.
get address(): string | null
get address(): string | null
This getter should return the wallet address as a string, or null
representing a failed state. While this is a getter for versatility, most implementations will want to use a backing field.
get provider(): ethers.providers.Web3Provider | null
get provider(): ethers.providers.Web3Provider | null
This getter should return the wallet provider or null
represent a failed state. While this should be implemented, the use of the provider directly is discouraged in favor of existing abstractions. While this is a getter for versatility, most implementations will want to use a backing field.
Metamask custom connector example:
Last updated