Below are the steps (take note, no issues when I test this on remix, it works absolutely fine)
- Two smart contracts, Usermapping.sol and CoffeeNetworking.sol
- in truffle "2_deploy_contract.js" enable Usermapping.sol inorder to deploy Usermapping.sol contract
- Then get the address of the Usermapping.sol of deployed contract.
- 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)
- Update the newly converted address in to CoffeeNetworking.sol.
- Then update truffle file "2_deploy_contract.js" to disbale Usermapping.sol deploy configuration and update with CoffeeNetowking.sol.
- Then finally truffle migrate for CoffeeNetworking.sol, no issues on deployment.
- For interaction, truffle console --network dev
- 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) })
- 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);
}