2

I am trying to call a function from deployed contract address using the below format

DeployedContractAddress.call(bytes4(keccak256("get(address)")),0xfffff);

But when trying to call the get(_address) using deployed contract address(without abi encoded), it should return an array. But here, it returns Boolean values true or false.

 function get(address _address) public returns (uint256[]){
 for(uint i=0;i<n;i++){
     arr[address].push(i);
 }
 return (arr);
}

Is there any simple way to get an array values without using ABI encoded?

2

According to the Solidity documentation, starting from version 0.5.0 it is possible to access the return data from a call:

address.call(bytes memory) returns (bool, bytes memory)

issue low-level CALL with the given payload, returns success condition and return data, forwards all available gas, adjustable

The data is given as a single bytes array, so you will likely want to decode it using abi.decode in order to make use of it.

Prior to version 0.5.0, you can count on the fact that the return values remains on the stack when the call() returns. They can be accessed, but you will have to use assembly.

0

The call method only returns a boolean value ( true / false ) based on the success it had calling said method.

If you want to read the "returned values" you need to deal with the ABI or you can do an assembly call and read and handle the values manually.

Check out How do I construct a call to another contract using inline assembly?

You can always specify an abstract interface for the abi you're going to use:

contract AbiInterface {
    function get(address _address) public returns (uint256[]);
}

function doIt() {
    AbiInterface myContract = AbiInterface.at(DeployedContractAddress);
    myContract.get(0xfffff);
}

But this of course does not work if you're trying to call arbitrary methods.

  • It's Ok if it returns true or false... When I copy my deployed code to some other system, it's working properly...But If I trying to call a function using deployed address nothing is happening...In ERC721, I tried to call transfer function,but nothing is reflecting. So What we have to do to resolve this issue? – lekshmi Jul 17 '18 at 12:36
  • you're going to have to share some code.. can't really make out the problem without that. – Micky Socaci Jul 18 '18 at 0:08
  • Thank you...Can you explain a little bit more? Did you mean ownable functions or full code sharing? – lekshmi Jul 18 '18 at 3:38
  • Your question states you want to retrieve values from a method in a contract that you have no "abi" for. This is cool if you're implementing a generic caller in which case you need to handle the return values in assembly based on the type you're expecting. On the other hand you're saying if the call returns a boolean value it's also fine. Which is it ? What are you actually trying to do with the code. Seeing it can help us help you or explaining what you want to accomplish could also help, just pick what you want to do :) – Micky Socaci Jul 18 '18 at 4:41
  • K sry.. I just want to call a function from already deployed contract address...because still nothing is happening when trying to call the functions from deployed contract address... :) – lekshmi Jul 18 '18 at 5:14

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.