[API Reference](../README.md) > [TransactionService](../classes/TransactionService.md)

# Class: TransactionService

Enables you to track the completion of transactions triggered by Arc.js functions. You can subscribe to events that tell you how many transactions are anticipated when the transactions have completed. For more information, see [Tracking Transactions](/Transactions.md).

## Hierarchy

 [PubSubEventService](PubSubEventService.md)

**↳ TransactionService**

## Index

### Methods

* [clearAllSubscriptions](TransactionService.md#clearAllSubscriptions)
* [generateInvocationKey](TransactionService.md#generateInvocationKey)
* [getConfirmedTransaction](TransactionService.md#getConfirmedTransaction)
* [getDefaultDepth](TransactionService.md#getDefaultDepth)
* [getMinedTransaction](TransactionService.md#getMinedTransaction)
* [getTransactionDepth](TransactionService.md#getTransactionDepth)
* [getValueFromLogs](TransactionService.md#getValueFromLogs)
* [isTopicSpecifiedBy](TransactionService.md#isTopicSpecifiedBy)
* [publish](TransactionService.md#publish)
* [publishTxFailed](TransactionService.md#publishTxFailed)
* [subscribe](TransactionService.md#subscribe)
* [unsubscribe](TransactionService.md#unsubscribe)
* [watchForConfirmedTransaction](TransactionService.md#watchForConfirmedTransaction)
* [watchForMinedTransaction](TransactionService.md#watchForMinedTransaction)

---

## Methods

<a id="clearAllSubscriptions"></a>

### `<Static>` clearAllSubscriptions

▸ **clearAllSubscriptions**(): `void`

*Inherited from [PubSubEventService](PubSubEventService.md).[clearAllSubscriptions](PubSubEventService.md#clearAllSubscriptions)*

*Defined in [pubSubEventService.ts:38](https://github.com/daostack/arc.js/blob/6f704389/lib/pubSubEventService.ts#L38)*

Remove all subscriptions

**Returns:** `void`

___
<a id="generateInvocationKey"></a>

### `<Static>` generateInvocationKey

▸ **generateInvocationKey**(): `number`

*Defined in [transactionService.ts:22](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L22)*

Generate a new invocation key.

**Returns:** `number`

___
<a id="getConfirmedTransaction"></a>

### `<Static>` getConfirmedTransaction

▸ **getConfirmedTransaction**(txHash: *[Hash](../#Hash)*, contract?: * `string` &#124; `any`*, requiredDepth?: *`number`*): `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) &#124; `null`>

*Defined in [transactionService.ts:344](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L344)*

Returns a promise of a TransactionReceipt for a confirmed transaction, or null if it hasn't yet been confirmed according to the requiredDepth.

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| txHash | [Hash](../#Hash) | - |  \- |
| `Default value` contract |  `string` &#124; `any`|  null |  Optional contract instance or contract name of the contract that generated the transaction. Supply this if you want decoded events. |
| `Optional` requiredDepth | `number` | - |  Optional minimum block depth required to resolve the promise. Default comes from the \`ConfigService\`. |

**Returns:** `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) &#124; `null`>

___
<a id="getDefaultDepth"></a>

### `<Static>` getDefaultDepth

▸ **getDefaultDepth**(requiredDepth?: *`number`*): `Promise`<`number`>

*Defined in [transactionService.ts:522](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L522)*

Returns the default value for required block depth defined for the current network in the Arc.js global configuration "[txDepthRequiredForConfirmation](/Configuration.md#txDepthRequiredForConfirmation)".

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| `Optional` requiredDepth | `number` |  Overrides the default if given |

**Returns:** `Promise`<`number`>

___
<a id="getMinedTransaction"></a>

### `<Static>` getMinedTransaction

▸ **getMinedTransaction**(txHash: *[Hash](../#Hash)*, contract?: * `string` &#124; `any`*, requiredDepth?: *`number`*): `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) &#124; `null`>

*Defined in [transactionService.ts:313](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L313)*

Returns a promise of a TransactionReceipt for a mined transaction, or null if it hasn't yet been mined.

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| txHash | [Hash](../#Hash) | - |  \- |
| `Default value` contract |  `string` &#124; `any`|  null |  Optional contract instance or contract name of the contract that generated the transaction. Supply this if you want decoded events. |
| `Default value` requiredDepth | `number` | 0 |  Optional minimum block depth required to resolve the promise. Default is 0. |

**Returns:** `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) &#124; `null`>
Promise of `TransactionReceiptTruffle` if contract is given, else `TransactionReceipt`,
or null if not found.

___
<a id="getTransactionDepth"></a>

### `<Static>` getTransactionDepth

▸ **getTransactionDepth**(tx: * [Hash](../#Hash) &#124; `TransactionReceipt`*): `Promise`<`number`>

*Defined in [transactionService.ts:281](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L281)*

Returns a promise of the number of blocks that have been added to the chain since the given transaction appeared. Use this to decide whether a transaction is sufficiently secure (confirmed).

See also [getConfirmedTransaction](/arc.js/api/classes/TransactionService#getConfirmedTransaction) and [watchForConfirmedTransaction](/arc.js/api/classes/TransactionService#watchForConfirmedTransaction).

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| tx |  [Hash](../#Hash) &#124; `TransactionReceipt`|  txHash or TransactionReceipt |

**Returns:** `Promise`<`number`>
Promise of the depth or -1 if the transaction cannot be found

___
<a id="getValueFromLogs"></a>

### `<Static>` getValueFromLogs

▸ **getValueFromLogs**(tx: * [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) &#124; `TransactionReceipt`*, arg: *`string`*, eventName?: *`string`*, index?: *`number`*):  `any` &#124; `undefined`

*Defined in [transactionService.ts:462](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L462)*

Returns a value from the given transaction log. Undefined if not found for any reason.

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| tx |  [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) &#124; `TransactionReceipt`| - |  The transaction |
| arg | `string` | - |  The name of the property whose value we wish to return from the args object: tx.logs\[index\].args\[argName\] |
| `Default value` eventName | `string` |  null |  Overrides index, identifies which log, where tx.logs\[n\].event === eventName |
| `Default value` index | `number` | 0 |  Identifies which log when eventName is not given |

**Returns:**  `any` &#124; `undefined`

___
<a id="isTopicSpecifiedBy"></a>

### `<Static>` isTopicSpecifiedBy

▸ **isTopicSpecifiedBy**(matchTemplates: * `Array`<`string`> &#124; `string`*, topic: *`string`*): `boolean`

*Inherited from [PubSubEventService](PubSubEventService.md).[isTopicSpecifiedBy](PubSubEventService.md#isTopicSpecifiedBy)*

*Defined in [pubSubEventService.ts:91](https://github.com/daostack/arc.js/blob/6f704389/lib/pubSubEventService.ts#L91)*

Return whether topic is specified by matchTemplates.

Examples:

matchTemplates: \["foo"\] topic: "foo.bar" result: true

matchTemplates: \["foo.bar"\] topic: "foo" result: false

Or a wildcard:

matchTemplates: "\*" topic: "foo" result: true

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| matchTemplates |  `Array`<`string`> &#124; `string`|  \- |
| topic | `string` |   |

**Returns:** `boolean`

___
<a id="publish"></a>

### `<Static>` publish

▸ **publish**(topic: *`string`*, payload: *`any`*): `boolean`

*Inherited from [PubSubEventService](PubSubEventService.md).[publish](PubSubEventService.md#publish)*

*Defined in [pubSubEventService.ts:18](https://github.com/daostack/arc.js/blob/6f704389/lib/pubSubEventService.ts#L18)*

Send the given payload to subscribers of the given topic.

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| topic | `string` |  See [subscribe](PubSubEventService.md#subscribe) |
| payload | `any` |  Sent in the subscription callback. |

**Returns:** `boolean`
True if there are any subscribers

___
<a id="publishTxFailed"></a>

### `<Static>` publishTxFailed

▸ **publishTxFailed**(eventContext: *`TxEventContext`*, atStage: *[TransactionStage](../enums/TransactionStage.md)*, error?: *`Error`*, tx?: *[Hash](../#Hash)*, txReceipt?: *[TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md)*): `void`

*Defined in [transactionService.ts:120](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L120)*

**Parameters:**

| Param | Type | Default value |
| ------ | ------ | ------ |
| eventContext | `TxEventContext` | - |
| atStage | [TransactionStage](../enums/TransactionStage.md) | - |
| `Default value` error | `Error` |  new Error(&quot;Unspecified error&quot;) |
| `Optional` tx | [Hash](../#Hash) | - |
| `Optional` txReceipt | [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md) | - |

**Returns:** `void`

___
<a id="subscribe"></a>

### `<Static>` subscribe

▸ **subscribe**(topics: * `string` &#124; `Array`<`string`>*, callback: *[EventSubscriptionCallback](../#EventSubscriptionCallback)*): [IEventSubscription](../interfaces/IEventSubscription.md)

*Inherited from [PubSubEventService](PubSubEventService.md).[subscribe](PubSubEventService.md#subscribe)*

*Defined in [pubSubEventService.ts:29](https://github.com/daostack/arc.js/blob/6f704389/lib/pubSubEventService.ts#L29)*

Subscribe to the given topic or array of topics.

**Parameters:**

| Param | Type | Description |
| ------ | ------ | ------ |
| topics |  `string` &#124; `Array`<`string`>|  Identifies the event(s) to which you wish to subscribe |
| callback | [EventSubscriptionCallback](../#EventSubscriptionCallback) |  The function to call when the requested events are published |

**Returns:** [IEventSubscription](../interfaces/IEventSubscription.md)
An interface with `.unsubscribe()`.  Be sure to call it!

___
<a id="unsubscribe"></a>

### `<Static>` unsubscribe

▸ **unsubscribe**(key: *[EventSubscriptionKey](../#EventSubscriptionKey)*, milliseconds?: *`number`*): `Promise`<`void`>

*Inherited from [PubSubEventService](PubSubEventService.md).[unsubscribe](PubSubEventService.md#unsubscribe)*

*Defined in [pubSubEventService.ts:52](https://github.com/daostack/arc.js/blob/6f704389/lib/pubSubEventService.ts#L52)*

Unsubscribes after optional timeout. When passed a token, removes a specific subscription, when passed a callback, removes all subscriptions for that callback, when passed a topic, removes all subscriptions for the topic hierarchy.

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| key | [EventSubscriptionKey](../#EventSubscriptionKey) | - |  A token, function or topic to unsubscribe. |
| `Default value` milliseconds | `number` |  -1 |  number of milliseconds to timeout. Default is -1 which means not to timeout at all. |

**Returns:** `Promise`<`void`>

___
<a id="watchForConfirmedTransaction"></a>

### `<Static>` watchForConfirmedTransaction

▸ **watchForConfirmedTransaction**(txHash: *[Hash](../#Hash)*, contract?: * `string` &#124; `any`*, requiredDepth?: *`number`*): `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md)>

*Defined in [transactionService.ts:254](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L254)*

Returns a promise of a TransactionReceipt once the given transaction has been confirmed according to the optional `requiredDepth`.

See also [getConfirmedTransaction](/arc.js/api/classes/TransactionService#getConfirmedTransaction) and [getTransactionDepth](/arc.js/api/classes/TransactionService#getTransactionDepth).

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| txHash | [Hash](../#Hash) | - |  The transaction hash to watch |
| `Default value` contract |  `string` &#124; `any`|  null |  Optional contract instance or contract name of the contract that generated the transaction. Supply this if you want decoded events. |
| `Optional` requiredDepth | `number` | - |  Optional minimum block depth required to resolve the promise. Default comes from the \`ConfigService\`. |

**Returns:** `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md)>

___
<a id="watchForMinedTransaction"></a>

### `<Static>` watchForMinedTransaction

▸ **watchForMinedTransaction**(txHash: *[Hash](../#Hash)*, contract?: * `string` &#124; `any`*, requiredDepth?: *`number`*): `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md)>

*Defined in [transactionService.ts:188](https://github.com/daostack/arc.js/blob/6f704389/lib/transactionService.ts#L188)*

Returns a promise of a TransactionReceipt once the given transaction has been mined.

See also [getMinedTransaction](/arc.js/api/classes/TransactionService#getMinedTransaction) and [getTransactionDepth](/arc.js/api/classes/TransactionService#getTransactionDepth).

**Parameters:**

| Param | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| txHash | [Hash](../#Hash) | - |  the transaction hash |
| `Default value` contract |  `string` &#124; `any`|  null |  Optional contract instance or contract name of the contract that generated the transaction. Supply this if you want decoded events. |
| `Default value` requiredDepth | `number` | 0 |  Optional minimum block depth required to resolve the promise. Default is 0. |

**Returns:** `Promise`< `TransactionReceipt` &#124; [TransactionReceiptTruffle](../interfaces/TransactionReceiptTruffle.md)>
Promise of `TransactionReceiptTruffle` if contract is given, else `TransactionReceipt`

___

