You're overlooking the mining step.
Contract deployment is the result of a transaction, but first a transaction has to mine. In the interim, the first response from sending a transaction, which new DepositPaying(address(this))
does, is a transaction hash.
That response doesn't indicate that the transaction is processed. Only that it was sent and assigned a UID. The transaction hash doesn't tell you anything about the address - just the transaction id you're interested in. It's up to the client to watch for the transaction to be mined and then observe what happened because that's where the address is.
There is a confusing array of approaches to your problem.
- The Truffle framework has a sophisticated Migrations system that tracks the addresses of contracts it deployed for you. Assuming you did
truffle migrate
and your migration script did deployer.deploy(DepositPaying)
, then you can get the instance conveniently with instance = DepositPaying.deployed()
and the address with instance.address
. This works great if you expect to deploy one instance of the contract.
- You can use the Web3 API to deploy and
.on('receipt
) to fire a callback (more like a promise) when the receipt is available (because it was mined) and something like getTransactionReceipt(txnHash) which includes the address of a deployed contract, if any, that came from your transaction.
- You can use a contract factory pattern to track it yourself. Using a contract factory has advantages. You can maintain an index of all the addresses created by the factory, make that easy to inspect, employ access control so your contracts only talk to other "trusted" contracts and emit events. If your factory emits events, then the front-end can just listen to contract creation events.
Consider:
contract DepositPaying {
...
}
contract Factory {
address[] public deployed;
event Deployed(address newContract);
function deployDepositPaying() public returns(address addr) {
addr = new DepositPaying(msg.sender);
deployed.push(addr);
emit Deployed(addr);
}
Some elaboration on the factory pattern: https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html?highlight=contract%20address#gettransactionreceipt
REMIX
The reason it all seems to work on Remix is that it "helps" by abstracting away some of the gory details. Transactions mine more or less immediately, it gets the receipts for you and it gives the response as through the front-end had dutifully attended to all of that stuff. These features make it much more productive to iterate over contract code, see what it does and get it right but it can create a false sense of simplicity when you move to front-end work without the training wheels.
Hope it helps.