Indexing proxy contracts
Proxy contracts are smart contracts that use the DELEGATECALL EVM instruction to forward calls to some of their methods to another contract (referred to as the implementation contract). This setup allows changing the code that runs on method calls without redeploying the contract and losing its state. Proxy contracts are standardized in ERC-1967. The easiest way to know if the contract is a proxy or not is to visit the “Contract” tab of its Etherscan page. Proxy contracts will typically have the “Read as Proxy” and “Write as Proxy” buttons available. Here is how it looks for the USDC contract: ) Clicking on the “Read as Proxy” button reveals the address of the implementation contract, FiatTokenV2_1 in this case. A few scenarios are possible when indexing a proxy contract:-
Events and calls that need to be indexed are described in the implementation contract. This is by far the most common use case. If that is what you need, simply use the implementation ABI to interface with the proxy contract. In our USDC example you would need to retrieve the ABI of the FiatTokenV2_1 contract, e.g. by running
That retrieves the ABI from Etherscan API and uses it to create TypeScript wrapper classes for implementation functions and events at ’./src/abi/fiatToken.ts`. Use these to subscribe to and decode the data of the proxy contract:./src/processor.tsComplete example is available here (uses./src/main.ts
Transfers instead ofMints). -
Events and calls that need to be indexed are described in the proxy contract itself. This typically occurs in indexers that track contract upgrades. In this case simply use the ABI of the proxy contract to both request and decode the data:
./src/processor.ts./src/main.ts
-
Events and call described in both contracts are needed. If that is your use case, retrieve ABIs of both the proxy and the implementation and use both:
./src/processor.ts

