# Execute

The execute function is responsible for applying changes from a successfully approved and queued proposal to the designated target contracts within the Onyx protocol. Once a proposal has passed the governance process and completed the Timelock delay period, it can be executed, implementing the proposed modifications.

#### Function Implementation in CHNGovernance

The `execute()` function ensures that only successful and properly queued proposals can be executed, enforcing governance integrity and protocol security.

#### Function Signature

<pre><code><strong>function execute(uint proposalId) public payable returns (uint)
</strong></code></pre>

#### Parameters

* `proposalId`: The unique identifier of the proposal to be executed. This proposal must have successfully passed governance voting, been queued, and completed the Timelock delay period.
* `RETURN`: The function does not return a value. If execution fails due to an invalid or non-queued proposal, it will revert with an error.

#### Example Solidity Implementation

To execute a proposal using Solidity, the `execute()`function can be called from an instance of the `CHNGovernance` contract:

```
CHNGovernance gov = CHNGovernance(0x123...); // Contract address of CHNGovernance
gov.execute(proposalId).value(999).gas(999)();
```

#### Web3.js Implementation (v1.2.6)

For interacting with the `CHNGovernance` contract using Web3.js, the following example demonstrates how to execute a proposal:

```javascript
const tx = await gov.methods.execute(proposalId).send({ from: sender, value: 1 });
```

#### Technical Considerations

* The execute() function is state-modifying and will incur gas costs.
* A proposal must have been successfully queued and completed the Timelock delay period before it can be executed.
* The function is payable, allowing the Timelock to invoke functions that require ETH transfers.
* If an attempt is made to execute an invalid, unqueued, or pending proposal, the transaction will revert with an error.
* The Timelock contract ensures security and decentralization, preventing immediate execution after proposal approval.


---

# 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.onyx.org/governance/execute.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.
