I'm trying to deploy a contract from another contract in solidity. The code is returning a valid address on localhost (with hardhat) but when I tried on Goerli network it return address 0x0000000000000000000000000000000000000000.
Here is the two contracts:
contract Test {
function test() external pure returns(uint256) {
return 10;
}
}
contract Factory {
address private addr;
constructor() {}
function DeployContract() public {
addr = address(new Test());
}
function getAddress() external view returns (address) {
return addr;
}
}
I am running the following script in JS :
const FactorySeed = await hre.ethers.getContractFactory("Factory");
const FactorySeedInstance = await FactorySeed.deploy();
await FactorySeedInstance.deployed();
console.log(`Deployed factory at ${FactorySeedInstance.address}`);
await FactorySeedInstance.DeployContract();
const address = await FactorySeedInstance.getAddress();
console.log("Test address " + address);
When running this on localhost node it work and return something like :
Deployed factory at 0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575
Test address 0x9FA5072032B7a7DCc49533401cec1C47bfcf350d
But on Goerli I get
Deployed factory at 0x742970731639e0830B2c7cD579d71018Fe93C683
Test address 0x0000000000000000000000000000000000000000
Can someone explain to me what I'm not understanding here ?
Simply because the RPC server are not updated with the latest data.
When calling the getAddress
function to the 0x742970731639e0830B2c7cD579d71018Fe93C683
address now, you can receive the 0xeA7bB92Fc218B930FA143954EE455A888E913162
address as the result. The same result can also be checked at internal txns.
In the local network, the node are updated instanly. But with an online network, you should wait for few blocks before getting data (to let the RPC updates).