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

# getOperation

> Retrieve a specific operation by ID

# getOperation

Retrieve a specific operation by its unique ID. This is a query method that doesn't modify state.

## Method Signature

```typescript theme={null}
getOperation: ActorMethod<[bigint], [] | [Operation]>
```

## Parameters

| Parameter | Type     | Required | Description                         |
| --------- | -------- | -------- | ----------------------------------- |
| `id`      | `bigint` | Yes      | The unique operation ID to retrieve |

## Response

Returns an optional `Operation`:

* `[]` - Operation not found
* `[Operation]` - Operation found

```typescript theme={null}
interface Operation {
  time: Time; // bigint timestamp
  typeof: OperationType;
}
```

### OperationType

Operations can be one of several types:

```typescript theme={null}
type OperationType = 
  | { access: { user: string } }
  | { token: { tokenid: TokenID, deltas: Array<Delta> } }
  | { trade: TradeOperation }
  | { other: { data: Metadata, name: string } }
  | { mint: { tokenid: TokenID, data: Metadata } }
  | { transaction: TransactionOperation }
```

For detailed type definitions, see the [getOperations](/canister/get-operations) documentation.

## Example Usage

### Basic Operation Lookup

```typescript theme={null}
const operationId = 12345n;
const result = await actor.getOperation(operationId);

if (result.length === 0) {
  console.log("Operation not found");
} else {
  const operation = result[0];
  console.log("Operation found:", operation);
  console.log("Timestamp:", operation.time);
  console.log("Type:", operation.typeof);
}
```

### Check Operation Type

```typescript theme={null}
const result = await actor.getOperation(12345n);

if (result.length > 0) {
  const operation = result[0];
  
  if ('trade' in operation.typeof) {
    const trade = operation.typeof.trade;
    console.log(`Trade: ${trade.user} ${trade.typeof.buy ? 'bought' : 'sold'} ${trade.amount_token} tokens`);
  } else if ('mint' in operation.typeof) {
    const mint = operation.typeof.mint;
    console.log(`Mint: Token ${mint.tokenid} was minted`);
  } else if ('transaction' in operation.typeof) {
    const tx = operation.typeof.transaction;
    console.log(`Transaction: ${tx.description} - ${tx.amount} tokens`);
  }
}
```

### Batch Operation Lookup

```typescript theme={null}
async function getMultipleOperations(ids: bigint[]) {
  const promises = ids.map(id => actor.getOperation(id));
  const results = await Promise.all(promises);
  
  const operations = results
    .map((result, index) => ({
      id: ids[index],
      operation: result.length > 0 ? result[0] : null
    }))
    .filter(item => item.operation !== null);
    
  return operations;
}

// Usage
const operationIds = [100n, 101n, 102n];
const operations = await getMultipleOperations(operationIds);
```

### Format Operation Timestamp

```typescript theme={null}
function formatOperationTime(operation: Operation): string {
  // Convert nanoseconds to milliseconds for JavaScript Date
  const milliseconds = Number(operation.time / 1_000_000n);
  const date = new Date(milliseconds);
  return date.toISOString();
}

const result = await actor.getOperation(12345n);
if (result.length > 0) {
  const operation = result[0];
  console.log("Operation time:", formatOperationTime(operation));
}
```

## Query Method

This is a **query method**, meaning:

* It doesn't modify canister state
* It's faster and cheaper to call
* Results are not certified (for certified data, use update calls)
* Can be called without authentication in some cases
