Solidity – Can’t Call Function in One Contract from Another

contract-deploymentcontract-developmentcontract-invocationsolidity

I'm trying to call a function in one contract from another contract with the following simple example:

Untitled.sol:

pragma solidity ^0.4.16;

contract helloworld {
function returnint() returns (uint) {
return 15;
}
}

And the second contract:

pragma solidity ^0.4.16;

import "./Untitled.sol";

contract pullother {

function callFunctionInContractOne (address _address) returns (uint) {
    helloworld contractOne = helloworld(_address);
    contractOne.returnint();
}
}

When calling callFunctionInContractOne() in the second contract, the address of the deployed Untitled.sol is given as a parameter, then the returnint() function in the first contract is called (which should return 15). When I try this in the remix editor I get the following returned instead:

enter image description here

I am copying from calling simple function from another contract but getting a different result. I've also tried running a function on one contract from another on a private blockchain in a similar way but am unsuccessful.

Adding a return value I get the same thing:

enter image description here

Best Answer

You actually sent a TX that call that method of the first smart contract, that called the function of the second smart contract. The thing is you are on a real blockchain - it seems Ropsten to me - and not in the memory of your computer, so you cannot retrieve values from a contract like that. What remix is returning to you is the transaction receipt after the block is mint.

If you want a ÐApp to be able to retrieve values directly from a contract, create functions with constant returns. And please note soon this constant will be split in view and pure.

Related Topic