# Proxy contracts

{% hint style="info" %}
For a step-by-step guide on shadowing a contract that uses a proxy pattern, see our [how-to on modifying proxy contracts](https://docs.shadow.xyz/modify-contracts/how-tos/proxy-contracts).
{% endhint %}

## What is a proxy contract?

A proxy contract in Ethereum is a smart contract that acts as an intermediary or wrapper for another contract, enabling features like upgradeability and interaction redirection.

Proxy contracts make delegate calls to a designated implementation contract, which contains the actual smart contract logic. This setup allows the logic (implementation contract) to be updated without changing the proxy contract's address, preserving the contract's state and address on the blockchain. Proxy contracts are a core component in creating upgradeable smart contracts.

## Do I write shadow events on the proxy or implementation?

If you want to get custom data for a contract that uses a proxy pattern, you'll need to modify the code of the implementation contract, because that's where the actual contract logic resides.

When transactions happen, events will get emitted by the proxy contract, while the event declarations and event emit logic reside in the code of the implementation contract. This is the same way other platforms that index smart contract data handle proxy patterns.

## Tips

### Add both the proxy and implementation contracts in Shadow

You will want to add both the proxy contract and implementation contract to your [Shadow Catalog](https://docs.shadow.xyz/product-guide/catalog), because you will need to:

* Edit the logic and add shadow events to the implementation contract
* View the event emits on the proxy contract

### How do I tell if a contract is a proxy contract?

On the Etherscan contract page, click on the `Contract` subtab. If you see the `Read as Proxy` tab, that means that this contract is a proxy contract.

Here's the Aave V3 Pool contract, which uses a proxy pattern, as an example.

<figure><img src="https://content.gitbook.com/content/S7wZ4G2hJbxyJhrQE8Kz/blobs/fw9dHTBpfsqOtGlN8WNP/Proxy.png" alt=""><figcaption><p><a href="https://etherscan.io/address/0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2#code">https://etherscan.io/address/0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2#code</a></p></figcaption></figure>

### How do I find a proxy contract's implementation contract?

Click on the `Read as Proxy` subtab. The current implementation contract address will be listed.

<figure><img src="https://content.gitbook.com/content/S7wZ4G2hJbxyJhrQE8Kz/blobs/U1O8B32dBsdbXFIR0e5W/Implementation.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://content.gitbook.com/content/S7wZ4G2hJbxyJhrQE8Kz/blobs/OoqGXKQ49T0BqKw1M8mo/Implementation%20Code.png" alt=""><figcaption></figcaption></figure>

### What do I do if a proxy has multiple past implementation contracts?

If you want to get shadow event data across a time period where the proxy contract has changed the implementation contract that it delegates its logic to, you will need to write separate shadow event logic on each implementation contract that was used during that time period.

This is because the logic across the previous implementation contracts could be different. Shadow will show your custom data from all implementation contracts on the proxy contract.


---

# 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.shadow.xyz/tips/proxy-contracts.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.
