getDelegatedImpl method

Future<Uint8List?> getDelegatedImpl(
  1. EthereumAddress eoa
)

Reads the on-chain bytecode of an externally owned account (EOA) and extracts the delegated implementation address if the account has been upgraded via EIP-7702.

This method checks whether the account code matches the minimal delegation stub:

0xEF 0x01 0x00 || <20-byte implementation address>

If the code matches this format, the function returns the final 20 bytes, representing the implementation address that the EOA is currently delegated to. Otherwise, null is returned.

A valid delegation stub must satisfy:

  • non-empty code
  • code length of exactly 23 bytes
  • first three bytes equal to 0xEF 0x01 0x00
  • remaining 20 bytes represent the delegated address

Example:

final impl = await getDelegatedImpl(myEoa);
if (impl != null) {
  print('EOA delegates to ${bytesToHex(impl)}');
}

See also:

Implementation

Future<Uint8List?> getDelegatedImpl(EthereumAddress eoa) async {
  const List<int> kStubPrefix = [0xEF, 0x01, 0x00];
  final code = await ctx.web3Client.getCode(eoa);
  if (code.isEmpty || code.length != 23) return null;

  for (var i = 0; i < kStubPrefix.length; i++) {
    if (code[i] != kStubPrefix[i]) return null;
  }
  return code.sublist(code.length - 20);
}