# submitReplaceAuthorityTx

> For the complete documentation index, see [llms.txt](https://docs.midnight.network/llms.txt)

[**Midnight.js API Reference v4.1.0**](https://docs.midnight.network/api-reference/midnight-js.md)

***

[Midnight.js API Reference](https://docs.midnight.network/api-reference/midnight-js/packages.md) / [@midnight-ntwrk/midnight-js-contracts](https://docs.midnight.network/api-reference/midnight-js/@midnight-ntwrk/midnight-js-contracts.md) / submitReplaceAuthorityTx

# Function: submitReplaceAuthorityTx()

> **submitReplaceAuthorityTx**<`C`>(`providers`, `compiledContract`, `contractAddress`): (`newAuthority`) => `Promise`<`FinalizedTxData`>

Constructs and submits a transaction that replaces the maintenance authority stored on the blockchain for this contract. After the transaction is finalized, the current signing key stored in the given private state provider is overwritten with the given new authority key.

## Transaction Execution Phases[​](#transaction-execution-phases "Direct link to Transaction Execution Phases")

Midnight transactions execute in two phases:

1. **Guaranteed phase**: If failure occurs, the transaction is NOT included in the blockchain
2. **Fallible phase**: If failure occurs, the transaction IS recorded on-chain as a partial success

## Failure Behavior[​](#failure-behavior "Direct link to Failure Behavior")

**Guaranteed Phase Failure:**

* Transaction is rejected and not included in the blockchain
* `ReplaceMaintenanceAuthorityTxFailedError` is thrown with transaction data
* Signing key in private state provider is NOT updated (remains as current authority)
* Contract authority on-chain remains unchanged

**Fallible Phase Failure:**

* Transaction is recorded on-chain with non-`SucceedEntirely` status
* `ReplaceMaintenanceAuthorityTxFailedError` is thrown with transaction data
* Signing key in private state provider is NOT updated (remains as current authority)
* Contract authority on-chain may be partially updated but inconsistent
* Transaction appears in blockchain history as partial success

## Type Parameters[​](#type-parameters "Direct link to Type Parameters")

### C[​](#c "Direct link to C")

`C` *extends* `Any`

## Parameters[​](#parameters "Direct link to Parameters")

### providers[​](#providers "Direct link to providers")

[`ContractProviders`](https://docs.midnight.network/api-reference/midnight-js/@midnight-ntwrk/midnight-js-contracts/type-aliases/ContractProviders.md)

The providers to use to manage the transaction lifecycle.

### compiledContract[​](#compiledcontract "Direct link to compiledContract")

`CompiledContract`<`C`, `any`>

The compiled contract for which the maintenance authority should be updated.

### contractAddress[​](#contractaddress "Direct link to contractAddress")

`string`

The address of the contract for which the maintenance authority should be updated.

TODO: There are at least three options we should support in the future:

1. Replace authority and maintain key (current).
2. Replace authority and do not maintain key.
3. Add additional authorities and maintain original key.

## Returns[​](#returns "Direct link to Returns")

> (`newAuthority`): `Promise`<`FinalizedTxData`>

### Parameters[​](#parameters-1 "Direct link to Parameters")

#### newAuthority[​](#newauthority "Direct link to newAuthority")

`string`

The signing key of the new contract maintenance authority.

### Returns[​](#returns-1 "Direct link to Returns")

`Promise`<`FinalizedTxData`>

A promise that resolves with the finalized transaction data, or rejects if an error occurs along the way.

### Throws[​](#throws "Direct link to Throws")

When transaction fails in either guaranteed or fallible phase. The error contains the finalized transaction data for debugging.
