2

Is Solidity creating an implicit getter or not for a nested contract that is created?

Example:

contract Foo {
   ....
}

contract Bar {
    Foo public foo;

   Bar() {
        foo = new Foo();
   }
}

When trying this out using Truffle, it tells me that Bar.foo() is not part of the ABI.

Am I doing something wrong, or is foo() just not being created by the Solidity compiler? (I'd expect it to return the address of the created Foo() contract)

0

If you have 2 contracts definition in one sol file, ContractA and ContractB, And you want to deploy ContracB, then use it like this:

var ContractB = artifacts.require("ContractB")

module.exports = function(deployer) {
  deployer.deploy(ContractB, '750000000000000000000000000', 'MyCoinName', 18,{gas: 4700000})
};

Note: .sol shouldn't be used and name of the contract to be deployed is used.

0

In Solidity 0.5.x you have explicitly cast a contract as an address. There is more than one way to write the function to return the contract address. To observe "implicitly" in the question ...

contract Foo {
   ....
}

contract Bar {
   Foo foo;
   address public fooAddress;

   Bar() {
        foo = new Foo();
        fooAddress = address(foo);
   }
}

So, thisContract.fooAddress() returns the address of foo.

Hope it helps.

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.