I have 2 contracts that can interact with each other:
contract ContractFoo {
address private _contractBarAddress;
constructor() {
}
function setContractBarAddress(address _address) public onlyOwner {
_contractBarAddress = _address;
}
function doSomething() public {
console.log("Bar is called");
Bar(_contractBarAddress).helloWorld();
}
}
contract Bar is Ownlable {
constructor() {}
function helloWorld() external {
// Possible check if it is the Foo calling it
console.log("Hello, world!");
}
}
Right now, after each deployment, I have to call setContractBarAddress
to interact with Bar
. Is there a way one could set it automatically directly in solidity? Right now the only way to automate is to write a custom function in e.g. Hardhat scripts to call such function.