2

I am very new to Solidty, and I am very confused ! I have the sample following code:

contract HelloSystem {

    address owner;

    // Constructor
    function HelloSystem(){
        owner = msg.sender;
    }

    function remove() {
        if (msg.sender == owner){
            selfdestruct(owner);
        }
    }
}

contract HelloFactory {

    function createHS() returns (address hsAddr) {
        return address(new HelloSystem());
    }

    function deleteHS(address hs){
        HelloSystem(hs).remove();
    }

}

It seems to compile fine with Remix but when I execute HelloFactory createHS, I got the output as the following:

Result: {
  "blockHash": "0x79a38504395749076aaad0b166eaee8b6f432dc7d880757b163d35ad6b8e17d1",
  "blockNumber": 25901,
  "contractAddress": null,
  "cumulativeGasUsed": 126668,
  "from": "0x6554c173718e20c84489ae563087787a5ebe2334",
  "gasUsed": 126668,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "root": "0x756e1a1139d2230556439930c7484de9cde3246e2e582e322e36c34e6c422eef",
  "to": "0xbbd6eebb731838296848b4983337e1a92f97cc89",
  "transactionHash": "0x8f3a32bf6520aa668eedfa1d68773cfd525bcfe21773aee81ccd50a2330cd2fd",
  "transactionIndex": 0
}
Transaction cost: 126668 gas. 

Where is the actual address of my HelloSystem contract ?! I don't understand where is the actually returned data.

4

I've added the CreatedHS(...) event and called this in createHS():

pragma solidity ^0.4.8;

contract HelloSystem {

    address owner;

    // Constructor
    function HelloSystem(){
        owner = msg.sender;
    }

    function remove() {
        if (msg.sender == owner){
            selfdestruct(owner);
        }
    }
}

contract HelloFactory {
    event CreatedHS(address indexed hsAddr);

    function createHS() returns (address hsAddr) {
        HelloSystem hs = new HelloSystem();
        CreatedHS(hs);
        return hs;
    }

    function deleteHS(address hs){
        HelloSystem(hs).remove();
    }

}

The following screen shows the address result logged with the CreatedHS(...) event:

enter image description here

The returned data from calling createHS() will be a transaction hash. After your transaction is mined into a block, you can retrieve the transaction result using eth.getTransactionReceipt(txHash), which is the output you listed in your question.

The easiest way to retrieve your newly created contract address is to log an event that includes this new address.

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.