> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://ensforge.com/api/mcp` to find what you need.

# enableHcaSessionWithRefund

Enable a session with an explicitly bounded refund.

## Import

```ts
import { enableHcaSessionWithRefund } from "@ensforge/core/hca";
```

## Usage

:::code-group
```ts [index.ts]
import { enableHcaSessionWithRefund } from "@ensforge/core/hca";
import { config } from "./config";
import { session } from "./session";

const result = await enableHcaSessionWithRefund(config, {
  ...session.parameters,
  refund: {
    token: "0x4567890123456789012345678901234567890123",
    maxExchangeRate: 1_000_000n,
    maxGasOverhead: 100_000n,
    maxAmount: 1_000_000n,
  },
});
```

```ts [config.ts]
// [!include ~/snippets/hca/config.ts]
```

```ts [session.ts]
import { execution } from "./execution";
import { config } from "./config";

export const session = await execution.extensions.sessions.prepare(config, {
  hca: "0x1234567890123456789012345678901234567890",
  resolver: "0x3456789012345678901234567890123456789012",
  validUntil: Math.floor(Date.now() / 1000) + 3600,
});
```
:::

## Parameters

```ts
import type { EnableHcaSessionWithRefundParameters } from "@ensforge/core/hca";
```

### refund

`HcaSessionRefund`

Explicit bound for session execution refunds.

### hca

`` `0x${string}` ``

HCA address to inspect or operate on.

### permissionId

`` `0x${string}` ``

Permission identifier of the prepared or enabled session.

### sessionKey

`` `0x${string}` ``

Address of the session signer. The private key is not passed to the action.

### validUntil

`number`

Session expiry as a Unix timestamp in seconds.

### resolver

`` `0x${string}` ``

Resolver address used by the registration or session policy.

### salt

`bigint | undefined`

Account derivation salt. Defaults to the deployment profile canonical salt.

### walletClient

`WalletClient | undefined`

Viem wallet override. Defaults to the configured wallet resolver.

### account

`` `0x${string}` | Account | undefined ``

Wallet account override for the operation.

## Return Type

```ts
import type { HcaTransactionSubmission } from "@ensforge/core/hca";
```

## Effect

Use `.effect` when composing the action in an Effect program. The success and error channels remain
fully typed.

```ts
import { Effect } from "effect";

const program = enableHcaSessionWithRefund.effect(config, {
  ...session.parameters,
  refund: {
    token: "0x4567890123456789012345678901234567890123",
    maxExchangeRate: 1_000_000n,
    maxGasOverhead: 100_000n,
    maxAmount: 1_000_000n,
  },
});

type Success = Effect.Success<typeof program>;
type Failure = Effect.Error<typeof program>;

const result = await Effect.runPromise(program);
```

## Call

```ts
const intent = enableHcaSessionWithRefund.call({
  ...session.parameters,
  refund: {
    token: "0x4567890123456789012345678901234567890123",
    maxExchangeRate: 1_000_000n,
    maxGasOverhead: 100_000n,
    maxAmount: 1_000_000n,
  },
});
```

Preparing an intent does not submit a transaction.

## Error

The Promise API rejects with the same typed failures exposed by the Effect error channel. Errors
have a stable `_tag`, `code`, and `message`; boundary errors retain their original `cause`.

See [Error Handling](/core/guides/error-handling).

## Related

* [`enableHcaSessionWithRefund`](/sdk/api/hca/enable-hca-session-with-refund)
* [Guide](/core/guides/hca)
