# tx Helpers

There are a number of helper functions to check the status of a transaction. See [useTx](https://use.ink/frontend/react/hooks/contracts/use-tx#transaction-state) for a full list of Transaction state values and descriptions.

### shouldDisable[​](https://use.ink/frontend/utils/tx-utils#shoulddisable) <a href="#shoulddisable" id="shoulddisable"></a>

This function that returns `true` if a transaction state is `DryRun`, `PendingSignature`, or `Broadcast`. It is good practice to disable a button that triggers a transaction unless it has fully resolved. In a successful transaction, `Broadcast` state comes immediately before `InBlock`, which is when contracts emit events and the transaction is most likely to succeed. See `shouldDisableStrict` if you want to disable a button until it is `Finalized`, which may be more appropriate for high stake dApps.

```javascript
import { shouldDisable } from 'useink';

export const Flipper = (contract) => {
    const flipTx = useTx(contract, 'flip');

    return (
        <button
            onClick={flipTx.signAndSend}
            disabled={shouldDisable(flipTx)}
        >
            {shouldDisable(flipTx) ? 'Flipping' : 'Flip!'}
        </button>
    )
}
```

### shouldDisableStrict[​](https://use.ink/frontend/utils/tx-utils#shoulddisablestrict) <a href="#shoulddisablestrict" id="shoulddisablestrict"></a>

This function that returns `true` if a transaction state is `DryRun`, `PendingSignature`, `Broadcast`, or `InBlock`. It is good practice to disable a button that triggers a transaction unless it has fully resolved.

```javascript
import { shouldDisableStrict } from 'useink';

//... React code omitted
<button
    onClick={flipTx.signAndSend}
    disabled={shouldDisableStrict(flipTx)}
>
    {shouldDisableStrict(flipTx) ? 'Flipping' : 'Flip!'}
</button>
```

### hasAny[​](https://use.ink/frontend/utils/tx-utils#hasany) <a href="#hasany" id="hasany"></a>

Returns a boolean if the transaction status has any of the arguments you pass in. Arguments must be of type `Status`;

```javascript
import { hasAny } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(hasAny(['Broadcast', 'Finalized']));
```

### isPendingSignature[​](https://use.ink/frontend/utils/tx-utils#ispendingsignature) <a href="#ispendingsignature" id="ispendingsignature"></a>

Returns a boolean if the transaction status is `PendingSignature`. `PendingSignature` is set when you call `signAndSend()` on a transaction, which opens up a browser wallet extension modal for a user to sign. Once the transaction is signed the state will change to `Broadcast`.

```javascript
import { isPendingSignature } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');
flipTx.signAndSend();

console.log(isPendingSignature(flipTx));
```

### isNone[​](https://use.ink/frontend/utils/tx-utils#isnone) <a href="#isnone" id="isnone"></a>

Returns a boolean if the transaction status is `None`.

```javascript
import { isNone } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isNone(flipTx));
```

### isDryRun[​](https://use.ink/frontend/utils/tx-utils#isdryrun) <a href="#isdryrun" id="isdryrun"></a>

Returns `true` if the transaction status is `DryRun`. `DryRun` occurs immediately before a transaction is sent to verify if it will succeed.

```javascript
import { isDryRun } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isDryRun(flipTx));
```

### isErrored[​](https://use.ink/frontend/utils/tx-utils#iserrored) <a href="#iserrored" id="iserrored"></a>

Returns a boolean if the transaction status is `Errored`, which means that there was an error in JavaScript somewhere.

```javascript
import { isErrored } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isErrored(flipTx));
```

### isFuture[​](https://use.ink/frontend/utils/tx-utils#isfuture) <a href="#isfuture" id="isfuture"></a>

Returns a boolean if the transaction status is `Future`, which means that the transaction is moving in to the transaction pool.

```javascript
import { isFuture } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFuture(flipTx));
```

### isReady[​](https://use.ink/frontend/utils/tx-utils#isready) <a href="#isready" id="isready"></a>

Returns a boolean if the transaction status is `Ready`, which means that the transaction is ready to be entered in to the transaction pool.

```javascript
import { isReady } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFuture(flipTx));
```

### isBroadcast[​](https://use.ink/frontend/utils/tx-utils#isbroadcast) <a href="#isbroadcast" id="isbroadcast"></a>

Returns a boolean if the transaction status is `Broadcast`. This is the point when events are emitted.

```javascript
import { isBroadcast } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isBroadcast(flipTx));
```

### isInBlock[​](https://use.ink/frontend/utils/tx-utils#isinblock) <a href="#isinblock" id="isinblock"></a>

Returns a boolean if the transaction status is `InBlock`. At this point it is very likely that the transaction will succeed. Most dApps can optimistically assume that the transaction is a success, but you may want to wait until `Finalized` stutus if you are building a high stakes dApp with monetary value so you can offer 100% guarantee that a transaction did succeed.

```javascript
import { isInBlock } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isInBlock(flipTx));
```

### isInvalid[​](https://use.ink/frontend/utils/tx-utils#isinvalid) <a href="#isinvalid" id="isinvalid"></a>

Returns a boolean if the transaction status is `Invalid`.

```javascript
import { isInvalid } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isInvalid(flipTx));
```

### isUsurped[​](https://use.ink/frontend/utils/tx-utils#isusurped) <a href="#isusurped" id="isusurped"></a>

Returns a boolean if the transaction status is `Usurped`.

```javascript
import { isUsurped } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isUsurped(flipTx));
```

### isDropped[​](https://use.ink/frontend/utils/tx-utils#isdropped) <a href="#isdropped" id="isdropped"></a>

Returns a boolean if the transaction status is `Usurped`.

```javascript
import { isDropped } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isDropped(flipTx));
```

### isFinalized[​](https://use.ink/frontend/utils/tx-utils#isfinalized) <a href="#isfinalized" id="isfinalized"></a>

Returns a boolean if the transaction status is `Finalized`. This status guarantees that a transaction completed.

```javascript
import { isFinalized } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFinalized(flipTx));
```

### isFinalityTimeout[​](https://use.ink/frontend/utils/tx-utils#isfinalitytimeout) <a href="#isfinalitytimeout" id="isfinalitytimeout"></a>

Returns a boolean if the transaction status is `FinalityTimeout`.

```javascript
import { isFinalityTimeout } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isFinalityTimeout(flipTx));
```

### isRetracted[​](https://use.ink/frontend/utils/tx-utils#isretracted) <a href="#isretracted" id="isretracted"></a>

Returns a boolean if the transaction status is `Retracted`.

```javascript
import { isRetracted } from 'useink';

//... React code omitted
const flipTx = useTx(contract, 'flip');

console.log(isRetracted(flipTx));
```
