Since v0.5.12, Solidity provides a CHAINID OPCODE in assembly:

function getChainID() external view returns (uint256) {
    uint256 id;
    assembly {
        id := chainid()
    return id;

Is there an equivalent in Vyper?

1 Answer 1


Since Vyper v0.1.0-beta15 the chain ID is available through the chain.id environment variable:

Here is a minimal example to verify the behavior:

def foo() -> uint256:
   return chain.id

Note that this is only possible if the compiler is set to target the Istanbul EVM ruleset or later.

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.