Home

Awesome

🌐 Extension Ecosystem

This repository is a treasure trove of extensions designed for integration with the Tatum SDK.

🚀 How to Use Extensions

Extensions are published as npm packages. You can install them like any other package. For example:

yarn add @tatumio/hello-world

During the Tatum SDK initialization phase, introduce the desired extension to the configureExtensions list:

const tatumSdk = await TatumSDK.init<Ethereum>({
    network: Network.ETHEREUM_SEPOLIA,
    configureExtensions: [
        HelloWorldExtension,
    ]
})

After that, you can use the extension in your code:

await tatumSdk.extension(HelloWorldExtension).sayHello()
await tatumSdk.extension(ConfigurableExtension).sayHelloWithConfiguration()

🛠️ Creating Extensions

TatumSdkExtension Abstract Class

All extensions must extend the TatumSdkExtension abstract class. This class provides the following:

export abstract class TatumSdkExtension {
    protected constructor(
        protected readonly tatumSdkContainer: ITatumSdkContainer) {
    }

    abstract supportedNetworks: Network[]

    init(): Promise<void> { return Promise.resolve(undefined) }
    destroy(): Promise<void> { return Promise.resolve(undefined) }
}

ITatumSdkContainer Interface

The ITatumSdkContainer interface provides access to the SDK configuration and internal sub-modules along with other registered extensions.

getRpc method provides access to the RPC sub-module of the SDK managed based on the SDK configuration (LoadBalancer, archive nodes, etc.).

export interface ITatumSdkContainer {
    get<T>(type: ServiceConstructor<T>): T
    getRpc<T>(): T
    getConfig(): TatumConfig
}

Example of extension constructor for extension depending on SDK configuration, FeeEvm sub-module and EvmRpc sub-module:

constructor(tatumSdkContainer: ITatumSdkContainer) {
    super(tatumSdkContainer)
    this.fee = this.tatumSdkContainer.get(FeeEvm)
    this.evmRpc = this.tatumSdkContainer.getRpc<EvmRpc>()
    this.sdkConfig = this.tatumSdkContainer.getConfig()
  }

User Configurable Extensions

If your extension needs to be configured by the user, you can pass any object to the extension constructor as the configuration.

constructor(tatumSdkContainer: ITatumSdkContainer, private readonly config: { configurationValue: string }) {
    super(tatumSdkContainer)
    this.fee = this.tatumSdkContainer.get(FeeEvm)
    this.sdkConfig = this.tatumSdkContainer.getConfig()
  }

Then during Tatum SDK initialization, you can pass the configuration object to the configureExtensions list:

const tatumSdk = await TatumSDK.init<Ethereum>({
    network: Network.ETHEREUM_SEPOLIA,
    configureExtensions: [
        HelloWorldExtension,
        {type: ConfigurableExtension, config: {configurationValue: 'CONFIGURED VALUE'}},
    ]
})

Wallet Provider Extensions

Wallet Provider Extensions is a special type of extension built on top of generic extension.

It provides a way to integrate with the Tatum SDK Wallet Provider accessible via tatum.walletProvider.use().

Wallet Provider Extensions must extend the TatumSdkWalletProvider<T,P> abstract class - check it here.

Then it can be used like this:

import { TatumSDK, Ethereum, Network, ApiVersion } from '@tatumio/tatum'
import { HelloWorldExtension } from "@tatumio/wallet-provider-demo"

const tatumSdk = await TatumSDK.init<Ethereum>({
    network: Network.ETHEREUM_SEPOLIA,
    configureWalletProviders: [
        WalletProviderDemo,
    ]
})

await tatumSdk.walletProvider.use(WalletProviderDemo).getWallet()

🔄 Extension Lifecycle

The extension lifecycle is managed by the Tatum SDK.

Base TatumSdkExtension includes empty implementation of those methods, if your extension require some initialization or destruction logic, you can override those methods.

🎨 Extension Showcases

📱 App Sample Incorporating Tatum SDK and Extensions