Solidity Function Call – Calling a Simple Function from Another Contract

contract-debuggingsolidity

I'm running into issues calling the function y() in the contract pullother. The input for the function y() is the output of the function g(). When I call y() using this input the output is blank ('' to be specific) rather than 15. I'm not exactly sure what I'm doing wrong here as this seems to align with the examples I see online of people successfully calling functions from other contracts.

The below is Untitled.sol

    pragma solidity ^0.4.6;

    contract helloworld {

    function f() returns (uint){
    return 15;
    }

    }

The below is the contract i would like to use to call the function f() in the contract helloworld.

pragma solidity ^0.4.6;

import "./Untitled.sol";

contract pullother {
address public hello;

function g() returns (address){
    hello = new helloworld();
    return hello;
}

function y(address contractadd) returns (uint){
    helloworld h = helloworld(contractadd);
    h.f();
}
}

Best Answer

I've tried your code in the solidity browser and it works

enter image description here

I think your need to use

return h.f()
Related Topic