0

Below are the steps (take note, no issues when I test this on remix, it works absolutely fine)

  1. Two smart contracts, Usermapping.sol and CoffeeNetworking.sol
    1. in truffle "2_deploy_contract.js" enable Usermapping.sol inorder to deploy Usermapping.sol contract
    2. Then get the address of the Usermapping.sol of deployed contract.
    3. Go to etherscan and convert the address to upper case.(if i dont do this step truffle compiler throws an error on invalid checksum address)
    4. Update the newly converted address in to CoffeeNetworking.sol.
    5. Then update truffle file "2_deploy_contract.js" to disbale Usermapping.sol deploy configuration and update with CoffeeNetowking.sol.
    6. Then finally truffle migrate for CoffeeNetworking.sol, no issues on deployment.
  2. For interaction, truffle console --network dev
  3. When i execute below function in truffle console, transaction goes through, CoffeeNetworking.at('0xfd95F4AF776ba4F0E6D13fEc18763cA59336494c').then(function(instance){ return instance.addValue(25)}).then(function(result){ console.log("Result", result) })
  4. In order to get the set value of above funciton, i execute below function, but could nt see the value of 25 result. (no issues if i use directly Usermapping.at(usermappingaddress) to execute the same funciton CoffeeNetworking.at('0xfd95F4AF776ba4F0E6D13fEc18763cA59336494c').then(function(instance){ return instance.getValue()}).then(function(result){ console.log("Result", result) })

//Usermapping.sol

pragma solidity ^0.4.23;
        contract Usermapping {
            uint256 public value;
            bytes32 public name;
            function addValue(uint a) public returns (bool)
            {
                value = a;
                return true;
            }
            function getValue() public view returns(uint256)
            {
                return value;
            }
            function setName(bytes32 nameSet) public returns(bool){
                name = nameSet;
                return true;
            }
             function getName() public view returns(bytes32){
                return name;
            }
        }

        var B = artifacts.require("./Usermapping.sol");
          module.exports = function(deployer){
        deployer.deploy(B)
       }

//CoffeeNetowkring.sol

pragma solidity ^0.4.23;

contract CoffeeNetworking{ 
    Usermapping u  = Usermapping(0x9B3a12cF7D8560DCd3d5D148cDCBCb9E1617D06F); 
    uint256 public version =1;
    // address add = 0x9B3a12cF7D8560DCd3d5D148cDCBCb9E1617D06F;  

    constructor () public {
    //   u = Usermapping(0xE1D685Fb942903986A9639da688d62E463BFC0DB);  
    }

    function addValue(uint a) public returns (bool){
        // Usermapping u = Usermapping(add);
        return u.addValue(a);
    }

    function getValue() public view returns (uint256){
        // Usermapping u = Usermapping(add);
        return u.getValue();
    }

    function setName(bytes32 name) public returns(bool){
        // Usermapping u = Usermapping(add);
        return u.setName(name);
    }

     function getName() public view returns(bytes32){
        // Usermapping u = Usermapping(add);
        return u.getName();
    }

}

contract Usermapping {
    uint256 public value;
    bytes32 public name;
    function addValue(uint a) public returns (bool);
    function getValue() public view returns(uint256);
    function setName(bytes32 nameSet) public returns(bool);
    function getName() public view returns(bytes32);
}

1 Answer 1

1

geth is returning transaction hash and remix is returning value. This is a fundamental difference in behavior of geth and remix. 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 either you should use solidity events or you should use calls in Ethereum.

Refer this blog to understand more about calls and transactions in solidity.

Refer to this blog for understanding more about solidity events.

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.