As shown here, is is possible to read the code of a contract using plain Solidity by using the .code member of the address type:

contract GetCode {
    function at(address _addr) public view returns (bytes memory o_code) {
        return _addr.code;

Does this return any code for precompiles?

1 Answer 1


The answer is no - The .code member does not return the code for precompiled addresses.

Let's take the following examples:

pragma solidity >=0.8.18;

contract Foo {
    function getCode1() external view returns (bytes memory) {
        address addr1 = address(1);
        return addr1.code;

    function getCode2() external view returns (bytes memory) {
        address addr2 = address(2);
        return addr2.code;

Calling either getCode1 or getCode2 returns a zero bytes array.

For more information about precompiles, see this other Q&A here on StackExchange: List of pre-compiled contracts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.