LogoLogo
Landing PageMarketplaceDeveloper PortalDeveloper Discord
  • 👋Welcome to Altura
  • Getting started
    • 🚀Altura NFTs
    • 🛍️The Altura Marketplace
    • 🪅Minting & Importing NFTs
    • 👔Users & Authentication
    • 🔑Altura Guard
  • 💻Developer Portal
    • 🧰The Developer Wallet
  • 🌐REST API
    • 🎴Get Your API Key
    • 🔧Methods
      • 🛡️Authenticate User
      • 👤Get User
      • 👥Get Users
      • 🖼️Get a User's Items
      • 🖼️Get Item
      • 🌈Get Items
      • 👾Get an Item's Holders
      • 📜Get an Item's History
      • 💠Transfer ERC1155
      • 💠Transfer ERC721
      • 💠Bulk Transfer ERC1155
      • 🔮Update an Item's Properties
      • ✍️Update an Item's data
      • 🧬Bulk Update an Item's Properties
      • 🪄Update an Item's Image
      • 📸Add a New Image
      • 🪟Mint Additional Supply
      • 📁Get Collection
      • 🗂️Get Collections
      • 🪄Update Collection
      • 🪙Transfer ERC20
      • ☑️Verify item Ownership
      • 🪙Check User's ERC20 Balance
      • 💰Check User's Balance
  • 🔆JavaScript SDK
    • 🛠️Installation
    • 🔧Methods
      • 🛡️Authenticate User
      • 👤Get User
      • 👥Get Users
      • 🖼️Get User's Items
      • 🖼️Get Item
      • 🌈Get Items
      • 👾Get an Item's Holders
      • 📜Get an Item's History
      • 💠Transfer ERC1155
      • 💠Transfer ERC721
      • 💠Bulk Transfer ERC1155
      • 🪟Mint Additional Supply
      • 🔮Update Property
      • 🪄Update Primary Image
      • 🆕Add a New Image
      • 📁Get Collection
      • 🗂️Get Collections
      • 🪄Update Collection
      • 🪙Transfer ERC20
    • 🎛️Schemas
    • ⌨️Connector API
  • 🕹️Unity SDK
    • 🛠️Installation
    • 🔧Methods
      • 🛡️Authenticate User
      • 👤Get User
      • 👥Get Users
      • 🖼️Get User's Items
      • 🖼️Get Item
      • 🌈Get Items
      • 👾Get an Item Holders
      • 📜Get an Item's History
      • 💠Transfer ERC1155
      • 💠Transfer ERC721
      • 💠Bulk Transfer ERC1155
      • 🪟Mint Additional Supply
      • 🔮Update Property
      • 🪄Update Primary Image
      • 📁Get Collection
      • 🗂️Get Collections
      • 🪄Update Collection
      • 🪙Transfer ERC20
    • 🎛️Schema
  • More
    • 🏷️White Label Marketplaces
    • 🛒List Your Game on the Altura Marketplace
    • ☑️Get Your Collection Verified
    • 🎁Create a Loot Box
  • 🎮Unreal SDK (ALPHA)
    • 🛠️Installation (Alpha)
    • 🛡️Authenticate User
    • 👤Get User
    • 👥Get Users
    • 🖼️Get Item
    • 🌈Get Items
    • 👾Get an Item's Holders
    • 📜Get an Item's History
    • 📁Get Collection
    • 📂Get Collections
    • 🪙Get User ERC20 balance
Powered by GitBook
On this page
  • Overview
  • Connector Interface
  • Using Connectors
  • Default Connectors
  • Writing Custom Connectors
  • Metamask custom connector example:

Was this helpful?

  1. JavaScript SDK

Connector API

PreviousSchemasNextInstallation

Last updated 2 years ago

Was this helpful?

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

export interface IConnector {
    get address(): string | null
    get provider(): ethers.providers.Web3Provider | null
    
    connect: () => Promise<string | null>
    sign: (message: string) => Promise<string | null>
}

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:

  • for

  • for

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>

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>

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

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

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:

import { IConnector } from './type';
import { ethers } from 'ethers';

export class MetamaskConnector implements IConnector {
  private _provider: ethers.providers.Web3Provider | null = null;
  private _address: string | null = null;

  public get provider() {
    return this._provider;
  }
  public get address() {
    return this._address;
  }

  /**
   * A basic constructor for connecting to MetaMask
   * @param ethereum The `window.ethereum` MetaMask instance
   */
  constructor(ethereum: ethers.providers.ExternalProvider | ethers.providers.JsonRpcFetchFunc) {
    this._provider = new ethers.providers.Web3Provider(ethereum);
  }

  public async connect(): Promise<string | null> {
    await this.provider?.send('eth_requestAccounts', []);
    this._address = (await this.provider?.getSigner()?.getAddress()) || null;
    return this.address;
  }

  public async sign(message: string): Promise<string | null> {
    return this.provider?.getSigner()?.signMessage(message) || null;
  }
}

🔆
⌨️
MetamaskConnector
Metamask
TrustwalletConnector
Trustwallet