1

Suppose I have a contract that creates and returns a new contract. Something like:

contract TokenFactory {
  function createToken() returns (Token) {
    return new Token();
  }
}

From my experience, if I call createToken() from another contract, I am not allowed to implicitly convert the returned contract object to type address, which makes me think the Token object is more than just an address.

If I pass this Token object as an argument to another function, will it cost more gas than passing just its address? Also, can the token object be put on the stack or must it be in memory/storage?

1

The returned Token argument is, in the EVM, just an address. All the additional semantics added, like accessing the functions of the address, are done at compile time. It shouldn't save any gas to return an address instead of the Token reference. That said, I didn't actually develop solc so I'm not sure. It should be pretty easy for you to test whether it costs more or not by just casting to address.

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.