Often for security reasons I want to limit certain address parameters to non-contract addresses for certain functions in my contracts, ie. there are no code stored on the addresses passed in as function parameters or as msg.sender, so to make sure the addresses are not some attack contracts that may try to exploit some re-entrancy vulnerabilities or conditionally congest the Ethereum network, etc. etc.

With solidity it seems the current de-facto standard way is to use inline assembly that checks if there are code stored on the address. Since Vyper has no inline assembly, is it possible for a Vyper contract to check if certain address parameters and/or the transaction sender are contracts or not?

  • Sometimes checking for codesize to be zero is not enough. While a constructor is executed the bytecode length will be zero, and it can make calls to other contracts.
    – Ismael
    Aug 9, 2019 at 17:08

2 Answers 2


yes you can just do _address.is_contract it will return true if it is a contract and false if it is not, you can read more at address type from vyper document: https://vyper.readthedocs.io/en/v0.1.0-beta.11/types.html


Right after posting this question I found out that in vyper the address type has a member called "codesize" which I guess can be used to check if an address is an active contract, and in the latest vyper version it seems even have a new member called "is_contract".

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.