Namespace proxies

Using WhatsABI to only resolve proxies with a known bytecode:

const address = "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. :)
const bytecode = "0x..."; // Already loaded from somewhere
const cachedCodeProvider = whatsabi.providers.WithCachedCode(provider, {
[address]: bytecode,
});

const result = 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.

Resolve a DiamondProxy:

// Let's say we have a result with a DiamondProxy in it, from the above example
const resolver = result.proxies[0] as whatsabi.proxies.DiamondProxyResolver;

// DiamondProxies have different contracts mapped relative to the selector,
// so we must resolve them against a selector.
const selector = "0x6e9960c3"; // function getAdmin() returns (address)

const implementationAddress = await resolver.resolve(provider, address, selector);

Get all facets and selectors for a DiamondProxy:

// Let's say we have a result with a DiamondProxy in it, from the above example
const diamondResolver = result.proxies[0] as DiamondProxyResolver;
const facets = await diamondResolver.facets(provider, address); // All possible address -> selector[] mappings

Index

Variables

Classes

Interfaces