1

I have seen here that:

Contract TokenCreator {
    function createToken(bytes32 name)
        public
        returns (OwnedToken tokenAddress)
    {
        // Create a new `Token` contract and return its address.
        // From the JavaScript side, the return type
        // of this function is `address`, as this is
        // the closest type available in the ABI.
        return new OwnedToken(name);
    }
    // some other code

}

From the function definition you can see that it returns a value of type OwnedToken how is this value type different from address type? Why not just say the return type is an address?

1 Answer 1

1

Because, the return type is not address but a contract (OwnedToken) with public methods and properties that you could call (from solidity).

On the javascript side or (other web3 client library), the closest type available in ABI is address (as mentioned in the comments in the code blocks of your question), so that is what it gets converted to.

2
  • Is this why when I emit an event, with address(tokenAddress) as a value, I get an error trying to decode it using etherjs? Like I have explained in this question.
    – YulePale
    Jul 19, 2021 at 14:21
  • 1
    address(tokenAddress) will give the address of the contract (explicitly converting the contract type to address). It is proper way, if the event is intended to emit an address parameter . Comments on the other question are added there
    – shonjs
    Jul 19, 2021 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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