> For the complete documentation index, see [llms.txt](https://nashpoint.gitbook.io/nashpoint/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nashpoint.gitbook.io/nashpoint/node-execute-function.md).

# Node Execute Function

The `execute` function enables valid Routers to make arbitrary contract calls on behalf of the Node, allowing for complex DeFi interactions while maintaining security controls.

```solidity
function execute(address target, bytes calldata data)
    external
    onlyRouter
    onlyWhenRebalancing
    returns (bytes memory)
{
    if (target == address(0)) revert ErrorsLib.ZeroAddress();
    bytes memory result = target.functionCall(data);
    emit EventsLib.Execute(target, data, result);
    return result;
}
```

#### Security Controls

* Only whitelisted routers can call `execute`
* Only works during rebalance window
* Target address cannot be zero
* Emits event with full call data and result

#### Common Usage

```solidity
// Example: Approve spending in router
function _safeApprove(address node, address token, address spender, uint256 amount) internal {
    bytes memory data = INode(node).execute(
        token, 
        abi.encodeCall(IERC20.approve, (spender, amount))
    );
    if (!(data.length == 0 || abi.decode(data, (bool)))) revert ErrorsLib.SafeApproveFailed();
}
```

#### Use Cases

* Token approvals
* Vault deposits/withdrawals
* Protocol-specific interactions
* Multi-step DeFi operations

All interactions must be implemented in the router contract, maintaining security through the whitelisting system.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://nashpoint.gitbook.io/nashpoint/node-execute-function.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
