How to get return value of external function?

0 votes

I have two functions funcA and funcB

function funcA(uint8 index) external view returns(uint8) {

    return someMapping[index];

}


function funcB() external view returns(bool) {

    return instanceOfA.getValueFor(1) == 1;

}

I want to get the return value of contract funcB. How to do this?

Aug 13, 2018 in Blockchain by slayer
• 29,050 points
25 views

1 answer to this question.

0 votes

You can do this. I have shared the code for it. I have checked it and it works.

pragma solidity >0.4.23 <0.5.0;


contract A {

    uint256 value;


    constructor(uint256 v) public {

        value = v;

    }


    function getValue() external view returns (uint256) {

        return value;

    }

}


contract B {

    A other;


    constructor(address a) public {

        other = A(a);

    }


    function getValueFromA() external view returns (uint256) {

        return other.getValue();

    }

}

Execution:

$ truffle console

truffle(development)> var aContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"getValue","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"v","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);


truffle(development)> var transObj = { from: web3.eth.accounts[0], data: '0x608060405234801561001057600080fd5b506040516020806100ea83398101806040528101908080519060200190929190505050806000819055505060a1806100496000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806320965255146044575b600080fd5b348015604f57600080fd5b506056606c565b6040518082815260200191505060405180910390f35b600080549050905600a165627a7a72305820dd332a08d090a6766cf7c2e86f41abc58a31e4d1afe7cb635a0a1b755a9b81cd0029', gas: '4700000'};


truffle(development)> var a = aContract.new(35, transObj);


truffle(development)> a.getValue();

BigNumber { s: 1, e: 1, c: [ 35 ] }


truffle(development)> var bContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"getValueFromA","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"a","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);


truffle(development)> transObj.data = '0x608060405234801561001057600080fd5b506040516020806101e783398101806040528101908080519060200190929190505050806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610164806100836000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680639b9be7cd14610046575b600080fd5b34801561005257600080fd5b5061005b610071565b6040518082815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663209652556040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b1580156100f857600080fd5b505af115801561010c573d6000803e3d6000fd5b505050506040513d602081101561012257600080fd5b81019080805190602001909291905050509050905600a165627a7a7230582096cc7381535016229911569ae3821103afb9a1ce582f3fc7bf226f3b5fac72380029';


truffle(development)> b = bContract.new(a.address, transObj);


truffle(development)> b.getValueFromA();

BigNumber { s: 1, e: 1, c: [ 35 ] }
answered Aug 13, 2018 by digger
• 27,640 points

Related Questions In Blockchain

0 votes
1 answer

How to get return value from solidity contract?

Once you call a constant function, you ...READ MORE

answered Aug 16, 2018 in Blockchain by slayer
• 29,050 points
465 views
+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,020 points
805 views
0 votes
1 answer

how to get modification history of asset?

You can use GetHistoryForKey() API as shown ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 27,640 points
327 views
0 votes
1 answer

How to write a program to get details of ERC tokens?

You can use Javascript with the Metamask ...READ MORE

answered Jul 13, 2018 in Blockchain by slayer
• 29,050 points
39 views
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,640 points
67 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
138 views
0 votes
1 answer

How to return data on execution of invoke function?

You can do this using a response ...READ MORE

answered Jul 23, 2018 in Blockchain by digger
• 27,640 points
34 views
0 votes
1 answer

How to get current value of bitcoin?

You can use json_decode to transform it ...READ MORE

answered Aug 20, 2018 in Blockchain by digger
• 27,640 points
49 views