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

Defined in: [atomiq-base/src/chains/ChainInterface.ts:40](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L40)

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

## Type Parameters

| Type Parameter                                                                                                                      | Default type                                                                                                     |
| ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| `TX`                                                                                                                                | `any`                                                                                                            |
| `SignedTX`                                                                                                                          | `any`                                                                                                            |
| `Signer` *extends* [`AbstractSigner`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/AbstractSigner.md) | [`AbstractSigner`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/type-aliases/AbstractSigner.md) |
| `ChainId` *extends* `string`                                                                                                        | `string`                                                                                                         |
| `NativeSigner`                                                                                                                      | `any`                                                                                                            |

## Properties

### chainId

```
readonly chainId: ChainId;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:51](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L51)

Chain identifier string

## Methods

### deserializeSignedTx()

```
deserializeSignedTx(txData): Promise<SignedTX>;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:153](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L153)

Deserializes a transaction from string

#### Parameters

| Parameter | Type     | Description                        |
| --------- | -------- | ---------------------------------- |
| `txData`  | `string` | Serialized transaction data string |

#### Returns

`Promise`<`SignedTX`>

***

### deserializeTx()

```
deserializeTx(txData): Promise<TX>;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:139](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L139)

Deserializes a transaction from string

#### Parameters

| Parameter | Type     | Description                        |
| --------- | -------- | ---------------------------------- |
| `txData`  | `string` | Serialized transaction data string |

#### Returns

`Promise`<`TX`>

***

### getBalance()

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

Defined in: [atomiq-base/src/chains/ChainInterface.ts:59](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L59)

Returns the token balance of a specific address

#### Parameters

| Parameter | Type     | Description                     |
| --------- | -------- | ------------------------------- |
| `signer`  | `string` | Address to check the balance of |
| `token`   | `string` | Token                           |

#### Returns

`Promise`<`bigint`>

***

### getFinalizedBlock()

```
getFinalizedBlock(): Promise<{

  blockHash: string;

  height: number;

}>;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:180](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L180)

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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L64)

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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L160)

Returns the transaction ID of the signed transaction

#### Parameters

| Parameter  | Type       | Description                                     |
| ---------- | ---------- | ----------------------------------------------- |
| `signedTX` | `SignedTX` | Signed 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L174)

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

#### Parameters

| Parameter | Type     | Description    |
| --------- | -------- | -------------- |
| `txId`    | `string` | Transaction 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L167)

Returns the status of the given serialized transaction

#### Parameters

| Parameter | Type     | Description            |
| --------- | -------- | ---------------------- |
| `tx`      | `string` | Serialized transaction |

#### Returns

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

***

### isValidAddress()

```
isValidAddress(address, lenient?): boolean;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:80](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L80)

Checks if a given string is a valid wallet address

#### Parameters

| Parameter  | Type      | Description                                                                                         |
| ---------- | --------- | --------------------------------------------------------------------------------------------------- |
| `address`  | `string`  |                                                                                                     |
| `lenient?` | `boolean` | Whether 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L94)

Checks if a given string is a valid token identifier

#### Parameters

| Parameter         | Type     | Description |
| ----------------- | -------- | ----------- |
| `tokenIdentifier` | `string` |             |

#### Returns

`boolean`

***

### normalizeAddress()

```
normalizeAddress(address): string;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:87](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L87)

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

#### Parameters

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `address` | `string` |             |

#### Returns

`string`

***

### offBeforeTxReplace()

```
offBeforeTxReplace(callback): boolean;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:219](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L219)

Remove tx replace callback

#### Parameters

| Parameter  | Type                                                          | Description |
| ---------- | ------------------------------------------------------------- | ----------- |
| `callback` | (`oldTx`, `oldTxId`, `newTx`, `newTxId`) => `Promise`<`void`> |             |

#### Returns

`boolean`

***

### onBeforeTxReplace()

```
onBeforeTxReplace(callback): void;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:212](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L212)

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

#### Parameters

| Parameter  | Type                                                          | Description |
| ---------- | ------------------------------------------------------------- | ----------- |
| `callback` | (`oldTx`, `oldTxId`, `newTx`, `newTxId`) => `Promise`<`void`> |             |

#### Returns

`void`

***

### prepareTxs()?

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

Defined in: [atomiq-base/src/chains/ChainInterface.ts:125](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L125)

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

#### Parameters

| Parameter | Type    | Description             |
| --------- | ------- | ----------------------- |
| `txs`     | `TX`\[] | 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L224)

Returns a random valid wallet address

#### Returns

`string`

***

### randomSigner()

```
randomSigner(): Signer;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:229](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L229)

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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L193)

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

#### Parameters

| Parameter              | Type                                   | Description                                                                                                                                  |
| ---------------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `signer`               | `Signer`                               | Signer to use for signing transactions                                                                                                       |
| `txs`                  | `TX`\[]                                | Transactions to send                                                                                                                         |
| `waitForConfirmation?` | `boolean`                              | Whether to wait for transaction confirmation (if parallel is not specified, every transaction's confirmation except the last one is awaited) |
| `abortSignal?`         | `AbortSignal`                          | Abort signal                                                                                                                                 |
| `parallel?`            | `boolean`                              | Whether 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L205)

Sends already signed transactions and optionally waits for their confirmation

#### Parameters

| Parameter              | Type                                   | Description                                                                                                                                  |
| ---------------------- | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `signedTxs`            | `SignedTX`\[]                          | Signed transactions to be sent                                                                                                               |
| `waitForConfirmation?` | `boolean`                              | Whether to wait for transaction confirmation (if parallel is not specified, every transaction's confirmation except the last one is awaited) |
| `abortSignal?`         | `AbortSignal`                          | Abort signal                                                                                                                                 |
| `parallel?`            | `boolean`                              | Whether 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L146)

Serializes a given transaction to a string

#### Parameters

| Parameter  | Type       | Description              |
| ---------- | ---------- | ------------------------ |
| `signedTX` | `SignedTX` | Transaction to serialize |

#### Returns

`Promise`<`string`>

***

### serializeTx()

```
serializeTx(tx): Promise<string>;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:132](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L132)

Serializes a given transaction to a string

#### Parameters

| Parameter | Type | Description              |
| --------- | ---- | ------------------------ |
| `tx`      | `TX` | Transaction to serialize |

#### Returns

`Promise`<`string`>

***

### shouldGetNativeTokenDrop()?

```
optional shouldGetNativeTokenDrop(tokenAddress): boolean;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:72](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L72)

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

#### Parameters

| Parameter      | Type     | Description |
| -------------- | -------- | ----------- |
| `tokenAddress` | `string` |             |

#### Returns

`boolean`

***

### transfer()

```
transfer(

   signer, 

   token, 

   amount, 

   dstAddress, 

txOptions?): Promise<string>;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:105](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L105)

Transfers the specific token to a given recipient

#### Parameters

| Parameter    | Type                             | Description                         |
| ------------ | -------------------------------- | ----------------------------------- |
| `signer`     | `Signer`                         | Signer/owner of the tokens          |
| `token`      | `string`                         | Token to transfer                   |
| `amount`     | `bigint`                         | Amount of token to transfer         |
| `dstAddress` | `string`                         | Destination address of the transfer |
| `txOptions?` | `TransactionConfirmationOptions` | Transaction options                 |

#### Returns

`Promise`<`string`>

***

### txsTransfer()

```
txsTransfer(

   signer, 

   token, 

   amount, 

   dstAddress, 

feeRate?): Promise<TX[]>;
```

Defined in: [atomiq-base/src/chains/ChainInterface.ts:116](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L116)

Returns transactions for transferring a specific token to a given recipient

#### Parameters

| Parameter    | Type     | Description                                                                      |
| ------------ | -------- | -------------------------------------------------------------------------------- |
| `signer`     | `string` | Signer/owner of the tokens                                                       |
| `token`      | `string` | Token to transfer                                                                |
| `amount`     | `bigint` | Amount of token to transfer                                                      |
| `dstAddress` | `string` | Destination address of the transfer                                              |
| `feeRate?`   | `string` | Optional 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L242)

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

| Parameter        | Type                                                                                                             |
| ---------------- | ---------------------------------------------------------------------------------------------------------------- |
| `bitcoinNetwork` | [`BitcoinNetwork`](https://docs.atomiq.exchange/sdk-reference/api/atomiq-sdk/src/enumerations/BitcoinNetwork.md) |

#### 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](https://github.com/atomiqlabs/atomiq-base/blob/df344bedbab9ab3de863e3c2d9246e90bd861d04/src/chains/ChainInterface.ts#L234)

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

#### Parameters

| Parameter | Type           |
| --------- | -------------- |
| `signer`  | `NativeSigner` |

#### Returns

`Promise`<`Signer`>
