0

In the below code, I re-create a handle on a contract by 'instantiating' it using its address. This works if I pass in a legit address (that really is the concerned contract type). How can I test if someone passes a contract address that is not the right contract type?

function changeOwnership(address aContract, address bAccount) returns (bytes32){
    MyContractType work = MyContractType(aContract);
    /* How would I do this?
     if (work is definitely a MyContractType contract){
           work.hasNewOwner(bAccount);
     }
     */
    return work.getWorkName();
}
  • If Solidity is statically typed, I'm guessing I cant do this. – Etienne Nov 16 '17 at 8:15
0

Solidity is a statically typed language. That means that the type of the contract must already be known for it to be used.

In the question asked, the solution would be to either have the child contract handle the transaction or keep a list (a mapping) of addresses and contract handle, so that when a new contract address is specified, retrieving its object handle is done by a look up in the mapping hash.

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.