1

I have seen that when I create a new smart contract from another smart contract Remix Ethereum return to me the address of smart contract. But When I do it with web3js the callback function just return to me a transactionHash and no more information. When I try to get eth.getTransactionReceipt("transactionHash") I saw contractAddress is null.

I can work arround by use event but my question is that How can Remix Ethereum can do that?

pragma solidity ^0.4.24;

contract Project {
    address public founder;
    constructor () public {
        founder = msg.sender;
    }
    function createRequest(string _title) public returns (address) {
        address addrRequest = new Request(_title);
        return addrRequest;
    }
}

contract Request {
    string public title;
    constructor(string _title) public {
        title = _title;
    }
}

Result from remix ethereum tool enter image description here

1 Answer 1

1

The return value of a sendTransaction method is always the hash of the transaction that’s created. Transactions don’t return a contract value to the front end because transactions are not immediately mined and included in the blockchain. To get values from a function you should use solidity events.

Refer to this blog for understanding more about solidity events.

Refer this question to understand why to write return statements in solidity function.

3
  • so that in remix tool it also use somehow a event to capture that information. Is it correct?
    – mai danh
    Commented Sep 13, 2018 at 6:38
  • No, currently you are using javascript vm of Remix with the help of which transaction is executed immediately. If you try to execute the same function on injected web3 you will get transaction hash. Commented Sep 13, 2018 at 7:00
  • Please refer the following documentation for more details remix.readthedocs.io/en/latest/run_tab.html Commented Sep 13, 2018 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.