> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# generateIdempotencyKey

> Generates a lowercase UUID v4 for use as an idempotency key on a transaction send.

## Function Signature

```dart theme={null}
String generateIdempotencyKey()
```

## Description

Generates an idempotency key for a transaction send. This is a top-level function exported by `package:portal_flutter/portal_flutter.dart`. It is not a method on `Portal`, so no wallet or client is required to call it.

The returned value is a lowercase UUID v4, which always meets Portal's key rules (1–255 characters of `A-Z a-z 0-9 . _ ~ -`).

Pass the result as `idempotencyKey` to `sendTransaction`, to `request` for `eth_sendTransaction`, `sol_signAndSendTransaction` or `sol_signAndConfirmTransaction`, or to `sendAsset` on EVM and Solana chains. Portal broadcasts a key at most once while it remembers the key (at least 24 hours after the request was last updated), so a retry with the same key within that time cannot send the same transaction twice.

## Parameters

None.

## Returns

**`String`** - A lowercase UUID v4, for example `"550e8400-e29b-41d4-a716-446655440000"`.

## Related Types

```dart theme={null}
abstract final class PortalIdempotencyErrorId {
  static const requestInProgress = 'IDEMPOTENT_REQUEST_IN_PROGRESS';
  static const requestAlreadyCompleted = 'IDEMPOTENT_REQUEST_ALREADY_COMPLETED';
  static const requestPreviouslyFailed = 'IDEMPOTENT_REQUEST_PREVIOUSLY_FAILED';
  static const requestUnexpectedState = 'IDEMPOTENT_REQUEST_UNEXPECTED_STATE';
  static const keyReused = 'IDEMPOTENCY_KEY_REUSED';
  static const txMissing = 'IDEMPOTENT_TX_MISSING';

  static const all = {
    requestInProgress,
    requestAlreadyCompleted,
    requestPreviouslyFailed,
    requestUnexpectedState,
    keyReused,
    txMissing,
  };
}
```

* `PortalIdempotencyErrorId` holds the error IDs Portal returns, as `PortalException.code`, when it rejects a request because of its key. `PortalException.isIdempotencyRejection` checks for any of them, and `PortalException.isIdempotencyKeyReused` checks for `keyReused`.
* Before anything is signed or sent, the SDK throws a `PortalException` with code `INVALID_IDEMPOTENCY_KEY` for a key that breaks the rules above, and `IDEMPOTENCY_KEY_UNSUPPORTED` for a key on `eth_sendRawTransaction`, `sol_sendTransaction` or a Bitcoin `sendAsset`.

## Example

```dart theme={null}
import 'package:portal_flutter/portal_flutter.dart';

final portal = Portal();

// Generate one key per transfer and store it with the pending transfer,
// so a retry can reuse it.
final idempotencyKey = generateIdempotencyKey();

try {
  final txHash = await portal.sendAsset(
    chainId: 'eip155:11155111',
    to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
    amount: '0.01',
    token: 'NATIVE',
    idempotencyKey: idempotencyKey,
  );

  print('Submitted — txHash: $txHash');
} on PortalException catch (e) {
  if (e.isIdempotencyRejection) {
    print('Portal already handled this key: ${e.code}');
  } else {
    print('Failed: [${e.code}] ${e.message}');
  }
}
```

## Notes

* Generate one key per operation, not per attempt. Reuse it only to retry the identical request.
* Portal remembers a key for at least 24 hours after the request was last updated, then removes it. Once the key is removed, the same key is treated as a new request, so check the chain before retrying an operation that is older than 24 hours.
* No rejection returns the original transaction hash. Check the chain before sending an operation again under a new key.

## Related

* [Idempotency keys guide](https://docs.portalhq.io/sdks/flutter/guide/idempotency-keys.md)
* [sendAsset](https://docs.portalhq.io/sdks/flutter/reference/sendasset.md)
* [sendTransaction](https://docs.portalhq.io/sdks/flutter/reference/sendtransaction.md)
* [request](https://docs.portalhq.io/sdks/flutter/reference/request.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.