2

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?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143

1 Answers1

3

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:

@public
@constant
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.

iamdefinitelyahuman
  • 2,876
  • 1
  • 12
  • 32