Skip to main content

TeleportSDK

The TeleportSDK class is an abstract class designed to provide a foundation on which specific implementations of the SDK for different blockchains can be built.

This class handles initial configuration, validation and management of Dapp modules. It is not intended to be used directly, but is expected to be extended by specific classes that implement its abstract methods.

Initialization

The initialize method is essential to prepare a new SDK instance, invoked by TeleportSDKFactory. This process sets the chain identifier (chainIdent), uses optional parameters to configure specific settings and prepares the SDK environment for operation. It also initializes a map to manage the Dapp modules and sets the isInitialized property to true to avoid reconfigurations. This method ensures that the SDK is ready to operate properly with the necessary settings for the specified blockchain.

Dapp Module Management

The TeleportSDK class provides a mechanism for managing Dapp modules. The class maintains a list of modules that have been registered with the SDK, and provides methods for adding, removing and accessing these modules.

By default the TeleportSDK class includes the ERC20, ERC721 and ERC1155 modules, which are designed to facilitate interactions with these types of tokens on Ethereum-based blockchains.

registerDapp

registerDapp(name: string, sdkModule: IDappSDK)

Registers a Dapp module with the SDK. The module is identified by a unique name, which is used to access the module later. The module must implement the IDappSDK interface, which defines the methods that the module must provide.

sdk.registerDapp("custom-erc20", new MyCustomErc20Module(sdk));

deregisterDapp

deregisterDapp(name: string)

Removes a Dapp module from the SDK. The module is identified by the name that was used when it was registered.

By default the TeleportSDK class includes the ERC20, ERC721 and ERC1155 modules, which are designed to facilitate interactions with these types of tokens on Ethereum-based blockchains. If you don't want to use these modules, you can deregister them.

import { ERC20RouterSDK } from "@stichting-allianceblock-foundation/abridge-sdk";

// Deregister the default ERC20 module
sdk.deregisterDapp(ERC20RouterSDK.DAPP_NAME);

// Deregister a custom ERC20 module
sdk.deregisterDapp("custom-erc20");

dapp

public dapp<DappType>(name: string): DappType

Returns a registered Dapp module by name. The module is identified by the name that was used when it was registered.

import { ERC20RouterSDK } from "@stichting-allianceblock-foundation/abridge-sdk";

const erc20Module = sdk.dapp<ERC20RouterSDK>(ERC20RouterSDK.DAPP_NAME);

Abstract Methods

Abstract methods in TeleportSDK form the backbone of its functionality and must be implemented by any blockchain-specific subclass. These methods define critical operations such as transmission delivery of transmissions, fee calculation, and support for provider contracts, among others. By requiring specific implementations for each blockchain, these methods allow the SDK to precisely adapt to the peculiarities and technical requirements of different networks. This ensures that the SDK can deliver consistent and optimized functionality for each blockchain environment in which it is deployed.

The abstract methods in TeleportSDK are as follows:

  • get utils(): TeleportHelperUtils

    Property getter that provides utilities to help with common operations, such as unit conversion or error handling. This getter method must be implemented by each specific SDK subclass.

  • getChainIdent(): Promise<string>

    Returns a string identifier that is specific to the blockchain implementation used. This identifier is critical to properly configure network interactions.

  • deliver(transmission: DeliverableTransmission, providerAddress?: string, options?: CallOptions): payableCall

    Performs the claim operation for a transmission.

  • getTeleportFee(): Promise<BigNumber>

    Calculates the fee associated with the use of the data or token teleport service.

  • getProviderFee({ targetChainId, transmissionReceiver, dAppId, payload }): Promise<BigNumber>

    Determines the fee that the service provider charges for the transaction.

  • getServiceFee({ targetChainId, transmissionReceiver, dAppId, payload }): Promise<BigNumber>

    Generally this method is the sum of the getTeleportFee and getProviderFee methods.

  • getProviderContract()

    Returns the provider contract used for transactions.

  • getProviderSupportedChains()

    Lists the blockchains that the provider supports.

  • getModuleByCollectionAddress(collectionAddress: string): Promise<typeof ERC1155RouterSDK | typeof ERC721RouterSDK | undefined>

    Returns the module that corresponds to the collection address.