Skip to main content

ChainInterface<TX, SignedTX, Signer, ChainId, NativeSigner>

Defined in: atomiq-base/src/chains/ChainInterface.ts:40

An interface representing a smart chain, allowing basic operations on the chain and reading chain data

Type Parameters

Type ParameterDefault type
TXany
SignedTXany
Signer extends AbstractSignerAbstractSigner
ChainId extends stringstring
NativeSignerany

Properties

chainId

readonly chainId: ChainId;

Defined in: atomiq-base/src/chains/ChainInterface.ts:51

Chain identifier string

Methods

deserializeSignedTx()

deserializeSignedTx(txData): Promise<SignedTX>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:153

Deserializes a transaction from string

Parameters

ParameterTypeDescription
txDatastringSerialized transaction data string

Returns

Promise<SignedTX>


deserializeTx()

deserializeTx(txData): Promise<TX>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:139

Deserializes a transaction from string

Parameters

ParameterTypeDescription
txDatastringSerialized transaction data string

Returns

Promise<TX>


getBalance()

getBalance(signer, token): Promise<bigint>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:59

Returns the token balance of a specific address

Parameters

ParameterTypeDescription
signerstringAddress to check the balance of
tokenstringToken

Returns

Promise<bigint>


getFinalizedBlock()

getFinalizedBlock(): Promise<{
blockHash: string;
height: number;
}>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:180

Returns the latest known finalized block data (this is a block with 100% certainty of not getting re-org, i.e. a block already committed on L1)

Returns

Promise<{ blockHash: string; height: number; }>


getNativeCurrencyAddress()

getNativeCurrencyAddress(): string;

Defined in: atomiq-base/src/chains/ChainInterface.ts:64

Returns the token address of the native currency of the chain

Returns

string


getTxId()?

optional getTxId(signedTX): Promise<string>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:160

Returns the transaction ID of the signed transaction

Parameters

ParameterTypeDescription
signedTXSignedTXSigned transaction to get the transaction ID of

Returns

Promise<string>


getTxIdStatus()

getTxIdStatus(txId): Promise<"not_found" | "pending" | "success" | "reverted">;

Defined in: atomiq-base/src/chains/ChainInterface.ts:174

Returns the status of the given transactionId (use getTxStatus whenever possible, it's more reliable)

Parameters

ParameterTypeDescription
txIdstringTransaction ID

Returns

Promise<"not_found" | "pending" | "success" | "reverted">


getTxStatus()

getTxStatus(tx): Promise<"not_found" | "pending" | "success" | "reverted">;

Defined in: atomiq-base/src/chains/ChainInterface.ts:167

Returns the status of the given serialized transaction

Parameters

ParameterTypeDescription
txstringSerialized transaction

Returns

Promise<"not_found" | "pending" | "success" | "reverted">


isValidAddress()

isValidAddress(address, lenient?): boolean;

Defined in: atomiq-base/src/chains/ChainInterface.ts:80

Checks if a given string is a valid wallet address

Parameters

ParameterTypeDescription
addressstring
lenient?booleanWhether a lenient parsing should be used (i.e. don't strictly enforce the Starknet address lengths)

Returns

boolean


isValidToken()

isValidToken(tokenIdentifier): boolean;

Defined in: atomiq-base/src/chains/ChainInterface.ts:94

Checks if a given string is a valid token identifier

Parameters

ParameterTypeDescription
tokenIdentifierstring

Returns

boolean


normalizeAddress()

normalizeAddress(address): string;

Defined in: atomiq-base/src/chains/ChainInterface.ts:87

Normalizes a given address i.e. pads it to the specific size

Parameters

ParameterTypeDescription
addressstring

Returns

string


offBeforeTxReplace()

offBeforeTxReplace(callback): boolean;

Defined in: atomiq-base/src/chains/ChainInterface.ts:219

Remove tx replace callback

Parameters

ParameterTypeDescription
callback(oldTx, oldTxId, newTx, newTxId) => Promise<void>

Returns

boolean


onBeforeTxReplace()

onBeforeTxReplace(callback): void;

Defined in: atomiq-base/src/chains/ChainInterface.ts:212

Callback called when transaction is being replaced (used for EVM, when fee is bumped on an unconfirmed tx)

Parameters

ParameterTypeDescription
callback(oldTx, oldTxId, newTx, newTxId) => Promise<void>

Returns

void


prepareTxs()?

optional prepareTxs(txs): Promise<TX[]>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:125

Prepares transaction for signing, by assigning a nonce, or a last valid blockhash

Parameters

ParameterTypeDescription
txsTX[]Transactions to prepare

Returns

Promise<TX[]>

Remarks

Ensure that all transactions are using the same signer, else this function might throw!


randomAddress()

randomAddress(): string;

Defined in: atomiq-base/src/chains/ChainInterface.ts:224

Returns a random valid wallet address

Returns

string


randomSigner()

randomSigner(): Signer;

Defined in: atomiq-base/src/chains/ChainInterface.ts:229

Returns randomly generated signer

Returns

Signer


sendAndConfirm()

sendAndConfirm(
signer,
txs,
waitForConfirmation?,
abortSignal?,
parallel?,
onBeforePublish?): Promise<string[]>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:193

Signs, sends a batch of transaction and optionally waits for their confirmation

Parameters

ParameterTypeDescription
signerSignerSigner to use for signing transactions
txsTX[]Transactions to send
waitForConfirmation?booleanWhether to wait for transaction confirmation (if parallel is not specified, every transaction's confirmation except the last one is awaited)
abortSignal?AbortSignalAbort signal
parallel?booleanWhether to send all transactions in parallel or one by one (always waiting for the previous TX to confirm)
onBeforePublish?(txId, rawTx) => Promise<void>Callback called before a tx is broadcast

Returns

Promise<string[]>


sendSignedAndConfirm()

sendSignedAndConfirm(
signedTxs,
waitForConfirmation?,
abortSignal?,
parallel?,
onBeforePublish?): Promise<string[]>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:205

Sends already signed transactions and optionally waits for their confirmation

Parameters

ParameterTypeDescription
signedTxsSignedTX[]Signed transactions to be sent
waitForConfirmation?booleanWhether to wait for transaction confirmation (if parallel is not specified, every transaction's confirmation except the last one is awaited)
abortSignal?AbortSignalAbort signal
parallel?booleanWhether to send all transactions in parallel or one by one (always waiting for the previous TX to confirm)
onBeforePublish?(txId, rawTx) => Promise<void>Callback called before a tx is broadcast

Returns

Promise<string[]>


serializeSignedTx()

serializeSignedTx(signedTX): Promise<string>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:146

Serializes a given transaction to a string

Parameters

ParameterTypeDescription
signedTXSignedTXTransaction to serialize

Returns

Promise<string>


serializeTx()

serializeTx(tx): Promise<string>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:132

Serializes a given transaction to a string

Parameters

ParameterTypeDescription
txTXTransaction to serialize

Returns

Promise<string>


shouldGetNativeTokenDrop()?

optional shouldGetNativeTokenDrop(tokenAddress): boolean;

Defined in: atomiq-base/src/chains/ChainInterface.ts:72

Whether a possibility for the user to get a native token "gas drop" should be provided if swapping to the provided token.

Parameters

ParameterTypeDescription
tokenAddressstring

Returns

boolean


transfer()

transfer(
signer,
token,
amount,
dstAddress,
txOptions?): Promise<string>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:105

Transfers the specific token to a given recipient

Parameters

ParameterTypeDescription
signerSignerSigner/owner of the tokens
tokenstringToken to transfer
amountbigintAmount of token to transfer
dstAddressstringDestination address of the transfer
txOptions?TransactionConfirmationOptionsTransaction options

Returns

Promise<string>


txsTransfer()

txsTransfer(
signer,
token,
amount,
dstAddress,
feeRate?): Promise<TX[]>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:116

Returns transactions for transferring a specific token to a given recipient

Parameters

ParameterTypeDescription
signerstringSigner/owner of the tokens
tokenstringToken to transfer
amountbigintAmount of token to transfer
dstAddressstringDestination address of the transfer
feeRate?stringOptional fee rate to use for the transaction (fetched on-demand if not provided)

Returns

Promise<TX[]>


verifyNetwork()?

optional verifyNetwork(bitcoinNetwork): Promise<void>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:242

Verifies whether the set network of this chain interface matches the passed bitcoin network (i.e. mainnet should use mainnet networks and testnets should use testnet networks)

Parameters

ParameterType
bitcoinNetworkBitcoinNetwork

Returns

Promise<void>

Throws

When the underlying network doesn't match


wrapSigner()

wrapSigner(signer): Promise<Signer>;

Defined in: atomiq-base/src/chains/ChainInterface.ts:234

Wraps a native chain signer object to an atomiq-understandable AbstractSigner

Parameters

ParameterType
signerNativeSigner

Returns

Promise<Signer>