MyReceiver my = MyReceiver(_to);    // To is an arbitrary address user provided
my.someFunction();                  // Do I need to check for my == null before calling?

Strange enough I do not see anyone doing so.


In solidity there is no such thing as a "null" (at least you can check if the passed address isn't a special one like 0x00)

MyReceiver my = MyReceiver(_to);

this line will store _to address in the variable my and indicates to the compiler that we are dealing with a contract (to construct the calls following the ABI). Its not like OOP objects!!

check it using this snippet code :

MyReceiver  c=MyReceiver(0x1234);
function test() view returns (address) {
 return c;

if you want t check if the contract exists you can use instead


to check if the size of the code at the given address is 0 or not.

  • Thanks Badr, how about the contract does exist, but doesn't has the someFunction() implement? – s k Jul 29 '18 at 10:00
  • this will trigger the fallback function in the called contract. otherwise the call will fail. besides if you find the previous answer helpfull think of accept it ;) we try to minimize bumped questions. – Badr Bellaj Jul 29 '18 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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