@multiplechain/types v0.1.55
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
9 days ago
13 days ago
14 days ago
14 days ago
20 days ago
20 days ago
20 days ago
20 days ago
21 days ago
21 days ago
21 days ago
21 days ago
21 days ago
21 days ago
21 days ago
21 days ago
21 days ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago