0.1.55 • Published 9 days ago

@multiplechain/types v0.1.55

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

MultipleChain Types

It is a suite of types defined to provide cross-network standardization in the MultipleChain project.

Installation

npm install @multiplechain/types

Usage

You can import all of the types at once:

import type * as types from '@multiplechain/types';

Or you import the types one by one:

import type {
    // Providers
    ProviderInterface,
    NetworkConfigInterface,

    // Models
    TransactionInterface,
    ContractTransactionInterface,
    AssetTransactionInterface,
    CoinTransactionInterface,
    TokenTransactionInterface,
    NftTransactionInterface,

    // Assets
    AssetInterface,
    ContractInterface,
    CoinInterface,
    TokenInterface,
    NftInterface,

    // Enums
    AssetDirectionEnum,
    TransactionTypeEnum,
    TransactionStatusEnum,

    // Transaction Listeners
    TransactionListenerInterface,
    DynamicTransactionType

    // Transaction Signer
    TransactionSignerInterface
} from '@multiplechain/types';

Types

Provider

ProviderInterface

Provider is the main class that will be used for every network (EVM, Solana, Tron, etc.)

ProviderInterface is the interface of Provider class.

NetworkConfigInterface

update() and constructor() methods of Provider class takes a config parameter. Interface of this config parameter is defined as NetworkConfigInterface.

Models

There are 6 types of transaction models:

TransactionInterface

TransactionInterface is the most comprehensive interface compared to others. Every other interface extends TransactionInterface.

This interface has ID management of transactions since each transaction and each transaction type has its own unique ID, and also has helper functions that is being used in every other transaction types such as getBlockNumber and getStatus

ContractTransactionInterface

Inherits TransactionInterface. Used for smart contracts transactions. Token and NFT transactions inherits ContractTransactionInterface.

On top of TransactionInterface, lets developers to grab smart contract address used in transaction.

getAddress: () => string // Smart contract address of the transaction

AssetTransactionInterface

Inherits TransactionInterface. Used for asset transactions.

CoinTransactionInterface

Used for transactions on blockchain done with native currency of the network. In other words, supports transaction data done on Layer-1 networks (Tron, Ethereum, Solana, etc.)

TokenTransactionInterface

Used for token transactions. Adds a support for verification of approvement on top of AssetTransactionInterface.

NftTransactionInterface

Used for NFT transactions. NFT transactions has a pointer property to NFT ID, NftTransactionInterface adds a helper method named getNftId() to grab that ID.

Also just like TokenTransactionInterface there is an approvement verification method in NftTransactionInterface too.

Assets

There are 5 types of asset interfaces

AssetInterface

AssetInterface is the most comprehensive interface compared to others. Every other interface except ContractInterface extends TransactionInterface.

It has helper methods like starting a transfer. transfer() method is available for every asset type (COINs, TOKENs, NFTs).

ContractInterface

ContractInterface is inherited by TokenInterface and NftInterface. It has helper methods like grabbing contract addresses.

CoinInterface

Used for coin assets. Currently adds a helper method to get decimal value of the asset on top of AssetInterface.

TokenInterface

Contains helper methods that can be used for grabbing token data like getTotalSupply().

NftInterface

Contains helper methods for NFT type of assets. Unlike the other asset interfaces, NftInterface overrides the transfer() method since it needs an nftId parameter instead of a amount parameter.

Enums

AssetDirectionEnum

Asset transactions (COIN, TOKEN, NFT) has two directions

enum AssetDirectionEnum {
    INCOMING,
    OUTGOING
}

TransactionTypeEnum

There are six types of transactions at the moment. COIN, TOKEN, and NFT transactions are called ASSET transactions

enum TransactionTypeEnum {
    GENERAL,
    CONTRACT,
    ASSET,
    COIN,
    TOKEN,
    NFT
}

TransactionStatusEnum

There are 3 available transaction statuses:

  • FAILED: When a transaction is failed
  • PENDING: When a transaction has not been concluded
  • CONFIRMED: When a transaction is confirmed
enum TransactionStatusEnum {
    FAILED,
    PENDING,
    CONFIRMED
}

Transaction Listener

TransactionListenerInterface

In order to listen to transactions whether they are PENDING or FAILED for instance, there needs to be a class providing methods for transaction listening.

TransactionListenerInterface is the interface of the TransactionListener class which supports gathering transaction status, stopping the transaction, and callbacks after a transaction status change.

DynamicTransactionType

There are different types of transactions, in order to listen correct transaction, correct transaction type needs to be provided. DynamicTransactionType is a helper interface that connects transaction types to their corresponding transaction interfaces

export type DynamicTransactionType<T extends TransactionTypeEnum> =
    T extends TransactionTypeEnum.GENERAL
        ? TransactionInterface
        : T extends TransactionTypeEnum.CONTRACT
          ? ContractTransactionInterface
          : T extends TransactionTypeEnum.COIN
            ? CoinTransactionInterface
            : T extends TransactionTypeEnum.TOKEN
              ? TokenTransactionInterface
              : T extends TransactionTypeEnum.NFT
                ? NftTransactionInterface
                : never

DynamicTransactionListenerFilterType

filter is an object that has values depending on transaction listener type. It has properties such as sender, receiver, etc.

Just like DynamicTransactionType, DynamicTransactionListenerFilterType is a helper interface to get correct filter type.

Transaction Signer

TransactionSignerInterface

Provides a class to sign and send transactions. TransactionSignerInterface has all of the methods to audit a signature.

Methods of TransactionSignerInterface are as follows:

Signs the transaction:

sign: (privateKey: string) => TransactionSignerInterface

Sends the signed transaction:

send: () => Promise<TransactionInterface | Error>

Returns unsigned transaction data

getRawData: () => any

Returns signed transaction data

getSignedData: () => any
0.1.55

9 days ago

0.1.53

13 days ago

0.1.52

14 days ago

0.1.51

14 days ago

0.1.50

20 days ago

0.1.46

20 days ago

0.1.47

20 days ago

0.1.48

20 days ago

0.1.36

21 days ago

0.1.37

21 days ago

0.1.41

21 days ago

0.1.42

21 days ago

0.1.43

21 days ago

0.1.44

21 days ago

0.1.45

21 days ago

0.1.40

21 days ago

0.1.38

21 days ago

0.1.31

1 month ago

0.1.35

1 month ago

0.1.30

1 month ago

0.1.27

1 month ago

0.1.28

1 month ago

0.1.29

1 month ago

0.1.24

1 month ago

0.1.25

1 month ago

0.1.26

1 month ago

0.1.22

1 month ago

0.1.23

1 month ago

0.1.20

2 months ago

0.1.21

2 months ago

0.1.19

2 months ago

0.1.18

2 months ago

0.1.15

2 months ago

0.1.16

2 months ago

0.1.17

2 months ago

0.1.14

2 months ago

0.1.11

2 months ago

0.1.12

2 months ago

0.1.13

2 months ago

0.1.10

2 months ago

0.1.8

2 months ago

0.1.7

2 months ago

0.1.9

2 months ago

0.1.4

2 months ago

0.1.6

2 months ago

0.1.5

2 months ago

0.1.3

2 months ago

0.1.2

2 months ago

0.1.1

2 months ago

0.1.0

2 months ago