Skip to content

createConnector

Creates a custom wallet connector for Reactive. Connectors handle the communication between your app and an Aeternity wallet.

Import

typescript
import { createConnector } from '@growae/reactive'

Usage

typescript
import { createConnector } from '@growae/reactive'

const myWallet = createConnector((config) => ({
  id: 'myWallet',
  name: 'My Wallet',
  type: 'injected',

  async connect() {
    // Establish connection to wallet
    const accounts = await this.getAccounts()
    return { accounts, networkId: 'ae_mainnet' }
  },

  async disconnect() {
    // Clean up wallet connection
  },

  async getAccounts() {
    // Return connected account addresses
    return ['ak_...']
  },

  async getProvider() {
    // Return the wallet provider/signer
  },

  async isAuthorized() {
    // Check if previously authorized
    return false
  },

  onAccountsChanged(accounts) {
    // Handle account switches
  },

  onNetworkChanged(networkId) {
    // Handle network switches
  },

  onDisconnect() {
    // Handle wallet disconnect
  },
}))

Connector Interface

Every connector must implement:

MethodReturn TypeDescription
connect{ accounts, networkId }Connect to the wallet
disconnectvoidDisconnect from the wallet
getAccountsstring[]Get connected accounts
getProviderAccountBaseGet signing provider
isAuthorizedbooleanCheck previous authorization

Events

Connectors emit events via the config.emitter:

EventPayloadDescription
connect{ accounts, networkId }Wallet connected
disconnectWallet disconnected
change{ accounts?, networkId? }Account or network changed
errorErrorConnector error

Built-in Connectors

ConnectorDescription
superhero()Superhero Wallet (browser extension + deeplink)
iframe()Iframe-based wallet communication
mock()Testing connector with configurable accounts