# Operation - OpenTrove

### Key Steps

1. **Chain and Account Validation**:
   * Ensures the operation is being performed on a supported chain and that a wallet account is connected.
2. **Set Referrer**:
   * Optionally sets a referrer if one is provided, validating the referrer details.
3. **Delegate Approval**:
   * Check if the delegate is approved, and if not, perform the approval.
4. **Collateral Checks**:
   * Verifies the user has enough ERC20 token balance and allowance to proceed with opening a trove.
5. **Open Trove**:
   * Executes the transaction to open a trove, calculating the total debt amount based on the minting amount.

### Usage

This function can be called with appropriate parameters to open a trove. It handles all necessary checks and operations to ensure the transaction is successfully executed.

### Example

```typescript
import { parseUnits, parseEther } from 'viem';
import { walletClient, publicClient, protocolConfig, collateral, wbtcABI, DEBT_TOKEN_DECIMALS } from 'satoshi-sdk';

// Step 1: Parse the minting amount and collateral amount
const mintingAmt = parseUnits('10', DEBT_TOKEN_DECIMALS); // Converts the string '10' into a BigNumber using the specified number of decimals
const totalCollAmt = parseEther('0.1'); // Converts the Ether string '0.1' to its Wei equivalent as a BigNumber

// Step 2: convert BEVM BTC to WBTC
const depositHash = await walletClient.writeContract({
  chain: protocolConfig.CHAIN,
  account: walletClient.account,
  address: collateral.ADDRESS,
  abi: wbtcABI,
  functionName: 'deposit',
  args: [],
  value: totalCollAmt,
});
await waitTxReceipt({ publicClient }, depositHash); // Wait for the transaction to be confirmed

// Step 3: Open a trove
const receipt = await satoshiClient.Postition.doOpenTrove({
  collateral,
  mintingAmt,
  totalCollAmt,
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.river.inc/satoshi-protocol-v1/sdk/position/operation-opentrove.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
