# API reference

* `buildETHTransaction`: Create Ethereum transactions.

  * Parameters:
    * req: A `PayloadBuildETHTransactionRequest` object containing the transaction details.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `Data` object containing the raw Ethereum transaction in serialized form, or `nil` if the operation fails.
  * Throws: This method can throw an error if the input parameters are invalid or if there are issues constructing the transaction.
  * Example:

  ```swift
  let request = PayloadBuildETHTransactionRequest()

  do {
      let transaction = try client.buildETHTransaction(request, error: nil)
      if let txData = transaction {
          print("Ethereum transaction built successfully.")
      } else {
          print("Failed to build Ethereum transaction.")
      }
  } catch {
      print("Error creating Ethereum transaction: \(error.localizedDescription)")
  }
  ```
* `buildSolTransaction`: Create Solana transactions.

  * Parameters:
    * req: A `PayloadBuildSolTransactionRequest` object containing the transaction details.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `Data` object containing the raw Solana transaction in serialized form, or `nil` if the operation fails.
  * Throws: This method can throw an error if the input parameters are invalid or if there are issues constructing the transaction.
  * Example:

  ```swift
  let request = PayloadBuildSolTransactionRequest()

  do {
      let transaction = try client.buildSolTransaction(request, error: nil)
      if let txData = transaction {
          print("Solana transaction built successfully.")
      } else {
          print("Failed to build Solana transaction.")
      }
  } catch {
      print("Error creating Solana transaction: \(error.localizedDescription)")
  }
  ```
* `buildTronTransaction`: Create Tron transactions.

  * Parameters:
    * req: A `PayloadBuildTronTransactionRequest` object containing the transaction details.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `Data` object containing the raw Tron transaction in serialized form, or `nil` if the operation fails.
  * Throws: This method can throw an error if the input parameters are invalid or if there are issues constructing the transaction.
  * Example:

  ```swift
  let request = PayloadBuildTronTransactionRequest()

  do {
      let transaction = try client.buildTronTransaction(request, error: nil)
      if let txData = transaction {
          print("Tron transaction built successfully.")
      } else {
          print("Failed to build Tron transaction.")
      }
  } catch {
      print("Error creating Tron transaction: \(error.localizedDescription)")
  }
  ```

`buildTonTransaction`: Create Ton transactions.

* Parameters:
  * req: A `PayloadBuildTonTransactionRequest` object containing the transaction details.
  * error: An optional pointer to an `Error` object to capture errors, if any.
* Returns:
  * A `Data` object containing the raw Ton transaction in serialized form, or `nil` if the operation fails.
* Throws: This method can throw an error if the input parameters are invalid or if there are issues constructing the transaction.
* Example:

```swift
let request = PayloadBuildTonTransactionRequest()

do {
    let transaction = try client.buildTonTransaction(request, error: nil)
    if let txData = transaction {
        print("Ton transaction built successfully.")
    } else {
        print("Failed to build Ton transaction.")
    }
} catch {
    print("Error creating Ton transaction: \(error.localizedDescription)")
}
```

`buildXrpTransaction`: Create Xrp transactions.

* Parameters:
  * req: A `PayloadBuildXrpTransactionRequest` object containing the transaction details.
  * error: An optional pointer to an `Error` object to capture errors, if any.
* Returns:
  * A `Data` object containing the raw Xrp transaction in serialized form, or `nil` if the operation fails.
* Throws: This method can throw an error if the input parameters are invalid or if there are issues constructing the transaction.
* Example:

```swift
let request = PayloadBuildXrpTransactionRequest()

do {
    let transaction = try client.buildXrpTransaction(request, error: nil)
    if let txData = transaction {
        print("Xrp transaction built successfully.")
        print("Raw Transaction Data: \(txData)")
    } else {
        print("Failed to build Xrp transaction.")
    }
} catch {
    print("Error creating Xrp transaction: \(error.localizedDescription)")
}
```

`buildBtcTransaction`: Create Btc transactions.

* Parameters:
  * req: A `PayloadBuildBtcTransactionRequest` object containing the transaction details.
  * error: An optional pointer to an `Error` object to capture errors, if any.
* Returns:
  * A `Data` object containing the raw Btc transaction in serialized form, or `nil` if the operation fails.
* Throws: This method can throw an error if the input parameters are invalid or if there are issues constructing the transaction.
* Example:

```swift
let request = PayloadBuildBtcTransactionRequest()

do {
    let transaction = try client.buildBtcTransaction(request, error: nil)
    if let txData = transaction {
        print("Btc transaction built successfully.")
    } else {
        print("Failed to build Btc transaction.")
    }
} catch {
    print("Error creating Btc transaction: \(error.localizedDescription)")
}
```

* `listBlockChainTransaction`: Fetch a list of blockchain transactions.

  * Parameters:
    * req: A `PayloadListBlockchainTransactionsRequest` object containing the parameters for filtering transactions. - `pageSize`: The number of transactions per page.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `PayloadListBlockchainTransactionsResponse` object containing the list of transactions and pagination metadata, or `nil` if the operation fails.
  * Throws: This method can throw an error if the request parameters are invalid or if there are runtime issues.
  * Example:

  ```swift
  let request = PayloadListBlockchainTransactionsRequest()

  do {
      let response = try client.listBlockChainTransaction(request, error: nil)
      if let transactions = response?.transactions {
          print("Retrieved \(transactions.count) transactions:")
      } else {
          print("No transactions found.")
      }
  } catch {
      print("Error fetching transactions: \(error.localizedDescription)")
  }
  ```
* `signing`: Perform signing operations for a given MPC group.

  * Parameters:
    * req: A `PayloadSigningRequest` object containing the details for the signing operation.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `Data` object containing the digital signature, or `nil` if the operation fails.
  * Throws: This method can throw an error if the signing request is invalid, if the group is misconfigured, or if there are runtime issues during the operation.
  * Example:

  ```swift
  let request = PayloadSigningRequest()

  do {
      let signature = try client.signing(request, error: nil)
      if let signedData = signature {
          print("Signing operation completed successfully.")
      } else {
          print("Signing operation failed.")
      }
  } catch {
      print("Error performing signing operation: \(error.localizedDescription)")
  }
  ```
* `profile`: Retrieve the user's profile.

  * Parameters:
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `ModelUser` object containing the user's profile information, or `nil` if the operation fails.
  * Throws: This method can throw an error if the user's profile is unavailable or if there are runtime issues.
  * Example:

  ```swift
  do {
      let userProfile = try client.profile(nil)
      if let profile = userProfile {
          print("User Profile Retrieved:")
      } else {
          print("No user profile found.")
      }
  } catch {
      print("Error retrieving user profile: \(error.localizedDescription)")
  }
  ```
* `saveUserSetting`: Save user-specific settings.

  * Parameters:
    * req: A `PayloadSaveUserSettingRequest` object containing the user settings to save.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A boolean value indicating whether the operation was successful (`true`) or not (`false`).
  * Throws: This method can throw an error if the request payload is invalid or if there are runtime issues.
  * Example:

  ```swift
  let request = PayloadSaveUserSettingRequest()
  request.key = "theme"
  request.value = "dark" // Example setting: User's preferred theme

  do {
      let success = try client.saveUserSetting(request, error: nil)
      if success {
          print("User setting saved successfully.")
      } else {
          print("Failed to save user setting.")
      }
  } catch {
      print("Error saving user setting: \(error.localizedDescription)")
  }
  ```
* `getUserSetting`: Retrieve user-specific settings.

  * Parameters:
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `Data` object containing the serialized user settings, or `nil` if the operation fails.
  * Throws: This method can throw an error if the settings cannot be retrieved or if there are runtime issues.
  * Example:

  ```swift
  do {
      let userSettingsData = try client.getUserSetting(nil)
      if let data = userSettingsData {
          print("User settings retrieved successfully.")
      } else {
          print("No user settings found.")
      }
  } catch {
      print("Error retrieving user settings: \(error.localizedDescription)")
  }
  ```
* `prepareAASmartAccount`: Prepare an Account Abstraction smart account.

  * Parameters:
    * req: A `PayloadPrepareAASmartAccountRequest` object containing the details for the smart account setup.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `PayloadAASmartAccount` object containing the details of the prepared smart account, including the account address and configuration, or `nil` if the operation fails.
  * Throws: This method can throw an error if the request is invalid, the network is unsupported, or there are runtime issues during the setup process.
  * Example:

  ```swift
  let request = PayloadPrepareAASmartAccountRequest()

  do {
      let smartAccount = try client.prepareAASmartAccount(request, error: nil)
      if let account = smartAccount {
          print("Smart account prepared successfully.")
          print("Account Address: \(account.accountAddress)")
          print("Network: \(account.network)")
      } else {
          print("Failed to prepare smart account.")
      }
  } catch {
      print("Error preparing smart account: \(error.localizedDescription)")
  }
  ```
* `prepareAATxUserOp`: Prepare a user operation for Account Abstraction transactions.

  * Parameters:
    * req: A `PayloadPrepareAATxUserOpRequest` object containing the details of the user operation to prepare.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `PayloadPrepareAATxUserOpResponse` object containing the prepared user operation, including details such as the encoded operation and required fields for signing, or `nil` if the operation fails.
  * Throws: This method can throw an error if the request parameters are invalid or if there are runtime issues during the preparation process.
  * Example:

  ```swift
  let request = PayloadPrepareAATxUserOpRequest()

  do {
      let userOpResponse = try client.prepareAATxUserOp(request, error: nil)
      if let operation = userOpResponse {
          print("User operation prepared successfully.")
          print("Encoded Operation: \(operation.encodedOperation)")
          print("Nonce: \(operation.nonce)")
      } else {
          print("Failed to prepare user operation.")
      }
  } catch {
      print("Error preparing user operation: \(error.localizedDescription)")
  }
  ```
* `sendUserOperation`: Sends a user operation to the blockchain for Account Abstraction (AA) transactions.

  * Parameters:
    * req: A `PayloadSendUserOperationRequest` object containing the details of the operation to execute.
    * error: An optional pointer to an `Error` object to capture errors, if any.
  * Returns:
    * A `String` object containing the transaction hash of the executed operation, or `nil` if the operation fails.
  * Throws: This method can throw an error if the request payload is invalid, the network is unavailable, or the operation fails during execution.
  * Example:

  ```swift
  let request = PayloadSendUserOperationRequest()

  do {
      let transactionHash = try client.sendUserOperation(request, error: nil)
      if let txHash = transactionHash {
          print("User operation sent successfully.")
          print("Transaction Hash: \(txHash)")
      } else {
          print("Failed to send user operation.")
      }
  } catch {
      print("Error executing user operation: \(error.localizedDescription)")
  }
  ```
* `exportMnemonic`: Retrieve wallet's Mnemonic phrase.

  * Parameters:
    * keygenGroupId: Master wallet's key generation group ID.
    * keyIdentities: The key identity of the wallet.
  * Returns:
    * A `String` containing your mnemonic, or `nil` if the operation fails.
  * Example:

  ```swift
  do {
      let mnemonic = try client.exportMnemonic("keygenGroupId", "keygenGroupId")
      print("Export mnemonic successfully.")
  } catch {
      print("Error retrieving to export Mnemonic : \(error.localizedDescription)")
  }

  ```
* `deleteMPCGroup` : Deletes a Paillier MPC group.

  * Parameters:
    * groupID: The unique identifier of the group to delete.
  * Throws: An error if the deletion fails.
  * Example:

  ```swift
  func main() {
      do {
          // Initialize the group ID
          let groupID = "keyGenGroupID"
          
          // Call deleteGroup to delete the group
          try deleteGroup(groupID: groupID)
          
          // Print success message
          print("Group with ID \(groupID) deleted successfully!")
      } catch {
          // Handle exceptions
          print("Failed to delete group: \(error.localizedDescription)")
      }
  }

  ```
* `getCurrentPolicy`: Retrieves the current policy as a publisher that emits \[Policy] objects.

  * Returns: An \[AnyPublisher] emitting \[Policy] objects.
  * Throws: An error if fetching the current policy fails.
  * Example:

  ```swift
  fun main() {
      var cancellables = Set<AnyCancellable>()
      Task {
          do {
              let policyPublisher = try await getCurrentPolicy()
              policyPublisher
                  .sink(receiveCompletion: { completion in
                      switch completion {
                      case .finished:
                          print("Successfully received policy.")
                      case .failure(let error):
                          print("Error: \(error)")
                      }
                  }, receiveValue: { policy in
                      print("Current policy: \(policy)")
                  })
                  .store(in: &cancellables)
          } catch {
              print("Failed to fetch policy with error: \(error)")
          }
      }
  }
  ```
* `enablePolicy`: Enables the current policy with a specified delay and an option to force the operation.

  * Parameters:
    * delayHours: The number of hours to delay before enabling the policy.
    * force: A boolean flag indicating whether to force enable the policy, overriding existing conditions.
  * Returns: An \[AnyPublisher] emitting the updated \[Policy] object.
  * Throws: An error if enabling the policy fails.
  * Example::

  ```swift
  fun main() {
      var cancellables = Set<AnyCancellable>()
      Task {
          do {
              let policyPublisher = try await enablePolicy(delayHours: 24, force: true)
              policyPublisher
                  .sink(receiveCompletion: { completion in
                      switch completion {
                      case .finished:
                          print("Policy enabled successfully.")
                      case .failure(let error):
                          print("Error enabling policy: \(error)")
                      }
                  }, receiveValue: { policy in
                      print("Updated policy: \(policy)")
                  })
                  .store(in: &cancellables)
          } catch {
              print("Failed to enable policy with error: \(error)")
          }
      }
  }
  ```
* `disablePolicy`: isables the current policy and returns a publisher that emits the updated \[Policy] object.

  * Returns: An \[AnyPublisher] emitting the updated \[Policy] object.
  * Throws: An error if disabling the policy fails.
  * Example:

  ```swift
  fun main() {
      var cancellables = Set<AnyCancellable>()
      Task {
          do {
              let policyPublisher = try await disablePolicy()
              policyPublisher
                  .sink(receiveCompletion: { completion in
                      switch completion {
                      case .finished:
                          print("Policy disabled successfully.")
                      case .failure(let error):
                          print("Error disabling policy: \(error)")
                      }
                  }, receiveValue: { policy in
                      print("Updated policy: \(policy)")
                  })
                  .store(in: &cancellables)
          } catch {
              print("Failed to disable policy with error: \(error)")
          }
      }
  }
  ```
* `addWalletAddress`: Adds a wallet address to the whitelist for a specific network chain with associated labels.

  * Parameters:
    * address: The wallet address to be added.
    * networkChain: The identifier for the blockchain network to which the address belongs.
    * labels: An array of labels to be associated with the wallet address.
  * Returns: An \[AnyPublisher] emitting the newly added \[Address] object.
  * Throws: An error if the wallet address cannot be added.
  * Example:

  ```swift
  fun main() {
  do {
      var cancellables = Set<AnyCancellable>()
      Task {
          do {
              let addressPublisher = try await addWalletAddress(
                  address: "0x123abc...",
                  networkChain: "ETH",
                  labels: ["whitelist", "verified"]
              )
              addressPublisher
                  .sink(receiveCompletion: { completion in
                      switch completion {
                      case .finished:
                          print("Wallet address added successfully.")
                      case .failure(let error):
                          print("Error adding wallet address: \(error)")
                      }
                  }, receiveValue: { address in
                      print("Added address: \(address)")
                  })
                  .store(in: &cancellables)
          } catch {
              print("Failed to add wallet address: \(error)")
          }
      }
  }
  ```
* `removeWalletAddress`: Removes the wallet address associated with the specified identifier.

  * Parameter walletId: The unique identifier of the wallet address to be removed.
  * Returns: An \[AnyPublisher] emitting an optional \[String] that indicates the result of the removal operation.
  * Throws: An error if the wallet address removal fails.
  * Example:

  ```swift
  fun main() {
      var cancellables = Set<AnyCancellable>()
      Task {
          do {
              let removalPublisher = try await removeWalletAddress(walletId: "walletId12345")
              removalPublisher
                  .sink(receiveCompletion: { completion in
                      switch completion {
                      case .finished:
                          print("Wallet address removed successfully.")
                      case .failure(let error):
                          print("Error removing wallet address: \(error)")
                      }
                  }, receiveValue: { removedId in
                      if let id = removedId {
                          print("Removed wallet address with id: \(id)")
                      } else {
                          print("No wallet address was removed.")
                      }
                  })
                  .store(in: &cancellables)
          } catch {
              print("Failed to remove wallet address with error: \(error)")
          }
      }
  }
  ```
* `updateWalletAddress`: Updates an existing wallet address with new labels.

  * Parameters:
    * walletId: The unique identifier of the wallet address to update.
    * labels: An array of new labels to associate with the wallet address.
  * Returns: An \[AnyPublisher] emitting the updated \[Address] object.
  * Throws: An error if updating the wallet address fails.
  * Example:

  ```swift
  fun main() {
      var cancellables = Set<AnyCancellable>()

      Task {
          do {
              let updatePublisher = try await updateWalletAddress(
                  walletId: "walletId12345",
                  labels: ["verified", "premium"]
              )
              updatePublisher
                  .sink(receiveCompletion: { completion in
                      switch completion {
                      case .finished:
                          print("Wallet address updated successfully.")
                      case .failure(let error):
                          print("Error updating wallet address: \(error)")
                      }
                  }, receiveValue: { address in
                      print("Updated address: \(address)")
                  })
                  .store(in: &cancellables)
          } catch {
              print("Failed to update wallet address with error: \(error)")
          }
      }
  }
  ```

`getTransactionAmountLimit`:  Retrieves the current transaction amount limit policy, including per-transaction and daily limits.

* Parameters: `None`
* Returns: An `AnyPublisher` emitting the current `TransactionLimitPolicy` object.
* Throws: An error if retrieving the transaction limit policy fails.
* Example:

```swift
import Combine

var cancellables = Set<AnyCancellable>()

let limitPublisher = getTransactionAmountLimit()
limitPublisher
    .sink(receiveCompletion: { completion in
        switch completion {
        case .finished:
            print("Successfully retrieved transaction amount limit.")
        case .failure(let error):
            print("Error retrieving transaction amount limit: \(error)")
        }
    }, receiveValue: { policy in
        print("Transaction Limit Policy:")
        print("- Per transaction: \(policy.perTransactionLimit)")
        print("- Daily limit: \(policy.dailyLimit)")
        print("- Enabled: \(policy.enable)")
    })
    .store(in: &cancellables)
```

`updateTransactionAmountLimit`:  Updates the transaction amount limit policy with new values for per-transaction and daily limits, and whether the policy is enabled.

* Parameters:&#x20;
  * `perTransactionLimit`: The maximum amount allowed per individual transaction (in smallest denomination).
  * `dailyLimit`: The maximum cumulative amount allowed per day.
  * `enable`: A Boolean value indicating whether the transaction limit policy is enabled.
* Returns: An `AnyPublisher<Void, Error>` indicating completion of the update operation.
* Throws: An error if retrieving the transaction limit policy fails.
* Example:

```swift
import Combine

var cancellables = Set<AnyCancellable>()

Task {
    do {
        let updatePublisher = try await updateTransactionAmountLimit(
            perTransactionLimit: 500000,
            dailyLimit: 5000000,
            enable: true
        )

        updatePublisher
            .sink(receiveCompletion: { completion in
                switch completion {
                case .finished:
                    print("Transaction amount limit updated successfully.")
                case .failure(let error):
                    print("Error updating transaction amount limit: \(error)")
                }
            }, receiveValue: {
                // No data returned on success (Void)
            })
            .store(in: &cancellables)

    } catch {
        print("Failed to update transaction amount limit with error: \(error)")
    }
}

```


---

# 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://cramiumlabs.gitbook.io/docs/sdk-mpc-ios/api-reference.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.
