Skip to main content

TeleportSDKFactory

The TeleportSDKFactory is an abstract class, it is not intended to be inherited from another class, but as a workaround so that it is not allowed to be instantiated directly. TeleportSDKFactory is designed to facilitate the creation of SDK instances tailored to different types of blockchains. Currently, the factory supports the creation of EvmTeleportSDK instances, which are designed for Ethereum-based blockchains.

Extending the SDK Factory

You can register a new dApp module in TeleportSDKFactory and, by doing so, you will be updating the factory configuration. This means that every new SDK instance created through the factory afterwards will automatically include this newly registered dApp module, provided that the conditions specified in the registration process are met.

By adding a new dApp module to the TeleportSDKFactory, you ensure that all future calls to create for generating new SDK instances will have the capability to utilize this new dApp. This design allows for seamless integration and scalability within the SDK architecture.

Future Extensions

As part of our ongoing development, the TeleportSDKFactory is planned to support additional blockchains in the future. Future classes like SolanaTeleportSDK and CosmosTeleportSDK will also extend from the base TeleportSDK. This architecture ensures that all specific SDK implementations maintain a consistent interface and can leverage common functionality provided by TeleportSDK. This approach not only streamlines the development of new blockchain-specific SDKs but also ensures that they adhere to a standardized framework, facilitating easier integration and maintenance.

Prerequisites

Before using the methods provided by the TeleportSDKFactory, ensure you have imported necessary constants and initialized a signer or provider. These steps are common for all the method examples provided below.

import {
constants,
TeleportSDKFactory,
} from "@stichting-allianceblock-foundation/abridge-sdk";

// Your wallet provider, useful for signing transactions
const signer = await new ethers.Wallet("0x...");

Adding a new dApp module

registerDapp

registerDapp(dappName: string, configurations: SDKModuleConfigurations<IDappSDK>)

As mentioned above, the registerDapp method allows you to register a new dApp module with the SDK factory. To do so, the name of the dApp module and the module-specific settings, which include the configuration conditions and the constructor of the dApp module, must be provided.

TeleportSDKFactory.registerDapp("myDapp", {
conditions: () => true,
constructor: (options) => {
return new MyDappSDK(options);
},
});

Create an instance of TeleportSDK

create

create(options: InitializationOptions): Promise<TeleportSDK>

Creates an instance of TeleportSDK based on the provided options. The options must include the type of chain (chainType), a provider or signer (signerOrProvider), and optional parameters that may include additional settings for specific modules. This function evaluates the SDK configuration conditions to determine the appropriate instance to create and initializes it with the provided parameters.

const sdk = await TeleportSDKFactory.create({
chainType: constants.ChainType.EVM,
signerOrProvider: signer,
});

createFromChainIdent

createFromChainIdent(chainIdentification: string | number, signerOrProvider: ValidProvider, optionalParams: TeleportOptionalParams): Promise<TeleportSDK> This method facilitates the creation of a TeleportSDK instance using a string identifier, which can be either a string name or an ID number. The method looks for the configuration corresponding to the provided string, and if valid, proceeds to create an instance of the SDK using the provided parameters.

Allowing either strings or numbers as chain identification will be especially useful in the future when the SDK supports other types of networks such as solana or cosmos.

const sdk = await TeleportSDKFactory.createFromChainIdent(
1, // Chain ID of Ethereum
signerOrProvider: signer
);

createFromMPCId

createFromMPCId(MPCId: number, signerOrProvider: ValidProvider optionalParams: TeleportOptionalParams): Promise<TeleportSDK> Similar to the previous method, but uses a MPCId (Messaging Protocol Chain ID) to identify the chain configuration.

const sdk = await TeleportSDKFactory.createFromMPCId(
1234, // Messaging Protocol Chain ID
signer
);