Using WhatsABI to only resolve proxies with a known bytecode:
constaddress = "0x...";
// Skip this and use the regular `provider` if you don't already have the bytecode or don't care about saving an RPC call. :) constbytecode = "0x..."; // Already loaded from somewhere constcachedCodeProvider = whatsabi.providers.WithCachedCode(provider, { [address]:bytecode, });
constresult = whatsabi.autoload(address, { provider:cachedCodeProvider, abiLoader:false, // Skip ABI loaders signatureLookup:false, // Skip looking up selector signatures })
if (result.address !== address) console.log(`Resolved proxy: ${address} -> ${result.address}`); if (result.proxies.length > 0) console.log("Proxies detected:", result.proxies); // Note that some proxies can only be resolved relative to a selector, like DiamondProxy. These will need to be resolved manually via result.proxies.
Example
Resolve a DiamondProxy:
// Let's say we have a result with a DiamondProxy in it, from the above example constresolver = result.proxies[0] aswhatsabi.proxies.DiamondProxyResolver;
// DiamondProxies have different contracts mapped relative to the selector, // so we must resolve them against a selector. constselector = "0x6e9960c3"; // function getAdmin() returns (address)
// Let's say we have a result with a DiamondProxy in it, from the above example constdiamondResolver = result.proxies[0] asDiamondProxyResolver; constfacets = awaitdiamondResolver.facets(provider, address); // All possible address -> selector[] mappings
Example
Using WhatsABI to only resolve proxies with a known bytecode:
Example
Resolve a DiamondProxy:
Example
Get all facets and selectors for a DiamondProxy: