function _createB() public {
    address newB = new B();
    newB(newB); //Event logs the address of contract B

When I copy and paste the address that is logged from the newB event into the "load contract at address" on Remix, I get another contract of type A.

How would I be able to create separate contracts of type B?


While trying to get contract of a particular type by "at address" that contract should be selected from the dropdown menu.

What happens in your case is that you get the contract of type "A" but it will still behave as contract of type "B".

What "at address" does:

It just provides an interface to the contract which is selected and which is expected to be deployed at the given address.

  • It finds which contract is selected for the operation of "at address"
  • It then finds the interface (ABI) of that contract from the code that is written in the current file.
  • Generates hashes of functions.
  • Displays each function name.
  • Whenever a function is called, the transaction data is prepared according to the hash of the function and sent to the contract.

Now if the contract has the ability to respond to that data, i.e., carry out that function, you get the correct output according to the contract at that address.

Note: This should be used with caution because if not used properly, you might end up interacting with another contract.

| improve this answer | |

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.