Repository navigation
Add Ethers.get_code/2 and EIP-7702 delegation helpers - #305
Merged
Merged
Conversation
- `Ethers.get_code/2` (+ bang) wraps `eth_getCode` with the same address
handling and `:block` override as `get_balance/2` and returns the code
as a binary (`""` for accounts without code). Also batchable as
`{:get_code, address}` / `{:get_code, address, block: block}`.
- New optional `eth_get_code/3` adapter callback; custom adapters without
it get `{:error, :not_supported}`.
- `Ethers.Authorization.parse_delegation/1` parses the delegate out of a
23-byte `0xef0100 ++ address` delegation designator.
- `Ethers.get_delegation/2` (+ bang) combines both, returning the
delegate or `nil` for accounts without a delegation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
`:get_balance` was missing from `@rpc_actions_map`, so batched balance requests were sent as the `get_balance` method and failed with "Method not found". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
`Ethers.deployed_address/2` now returns EIP-55 checksummed addresses, so the delegate returned by `get_delegation/2` must equal it as is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
alisinabh
force-pushed
the
feat/get-code-and-delegation
branch
from
November 15, 2026 23:15
119ee7f to
ae6609f
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a wrapper for
eth_getCodeand helpers to inspect EIP-7702 delegations. Authorizations with a wrong nonce are skipped silently on chain, so reading the authority's code afterwards is the only way to know whether a delegation took effect.API
Ethers.get_code(address, overrides \\ [])/get_code!/2: wrapseth_getCode. Address handling and the:blockoverride (integer or block tag),:rpc_clientand:rpc_optswork as inEthers.get_balance/2. Returns the code as raw bytes:{:ok, ""}for an account without code, and the 23-byte delegation designator for a delegated EOA.{:get_code, address}/{:get_code, address, block: block}inEthers.batch/2.eth_get_code/3callback on the RPC client adapter, checked withfunction_exported?/3. Existing custom adapters keep compiling; without the callbackget_code/2returns{:error, :not_supported}, likeeth_fee_history/4,eth_create_access_list/3andeth_config/1.Ethereumex.HttpClientalready provideseth_get_code/3, so the default adapter delegates to it unchanged.Ethers.Authorization.parse_delegation(code): pure. Returns{:ok, delegate_address}(checksummed) whencodeis exactly0xef0100 ++ address(23 bytes),:errorotherwise (empty code, contract code, any other length). Takes raw bytes only, no hex strings. Same rule as go-ethereum'stypes.ParseDelegation.Ethers.get_delegation(address, overrides \\ [])/get_delegation!/2:get_code/2+parse_delegation/1. Returns{:ok, delegate_address}when delegated,{:ok, nil}when the account has no delegation (both an account without code and a regular contract),{:error, reason}on RPC failure.The
Ethers.Authorizationmoduledoc now points to these where it explains that a mismatched nonce silently skips the authorization.EIP-7702 text relied on
From the authorization processing steps (EIP status: Final):
and the length: "
EXTCODESIZEreturns23(the size of0xef0100 || address)".So a cleared account has empty code (
get_code/2returns"",get_delegation/2returnsnil).parse_delegation/1only checks the format, so a designator for the zero address (which conforming chains never write) parses to the zero address.Tests
parse_delegation/1: valid designator, empty code, contract bytecode, 22 and 24 bytes, bare prefix, 23 bytes with a wrong prefix, zero-address designator, hex string input.get_code/2:"");:blockoverride before and after deployment;:not_supported.get_delegation/2:nilfor an EOA and a contract, error propagation."",get_delegation/2returnsnil;get_code/2returns0xef0100 ++ delegate,get_delegation/2returns the delegate, and querying the block before returnsnil;""again andget_delegation/2returnsnil.Included fix
:get_balancewas missing from the batch action map, so{:get_balance, address}inEthers.batch/2was sent as theget_balancemethod and failed with "Method not found". It is now mapped toeth_getBalance, with a batch test.Notes
Local tests ran against anvil 1.6.0-nightly with cached test contract ABIs (the local solc is broken). CI runs anvil 1.9.0.
Closes #293
🤖 Generated with Claude Code
https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6