1

Example:

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.

1 Answer 1

0

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

extcodesize(a)  

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

2
  • Thanks Badr, how about the contract does exist, but doesn't has the someFunction() implement?
    – s k
    Jul 29, 2018 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, 2018 at 10:43

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.