I have written a contract Transfer
and the functions defined in the contract Transfer
is used in another contract SecondTransfer
.I have defined a constructor in the contract Transfer
and initialized values in that constructor.
pragma solidity ^0.4.2;
contract Transfer {
address public userA;
address public user;
mapping (address => uint) balances;
uint value2;
// constructor
function Transfer() {
userA=msg.sender;
balances[userA]=1000;
}
function sendEther(address user,uint value)returns (bool success){
if(balances[userA]< value){
return false;
}
else {
balances[userA] -= value;
balances[user] += value;
return true;
}
}
function sendAddressToAddress(address fromuser,address touser)returns (bool success){
uint value=balances[fromuser];
if(value < 0){
return false;
}
else {
balances[fromuser] -= value;
balances[touser] += value;
return true;
}
}
function getBalance(address user) returns (uint _balance){
return balances[user];
}
}
contract SecondTransfer {
function sendEtherCall(address contractaddr,address user,uint value) returns (bool success) {
Transfer transfer=Transfer(contractaddr);
return transfer.sendEther(user,value);
}
function sendAddressToAddressCall(address contractaddr,address fromuser,address touser) returns (bool success) {
Transfer transfer=Transfer(contractaddr);
return transfer.sendAddressToAddress(fromuser,touser);
}
function getBalanceCall(address contractaddr,address user) returns (uint _balance) {
Transfer transfer=Transfer(contractaddr);
return transfer.getBalance(user);
}
}
I have tried to run this contract using browser-solidity. I have passed the address of the contract Transfer
as parameter to the contract Second Transfer
. But the function getBalanceCall
returns a VMException error.
Please do help me to rectify the issues. Is there any issues regarding constructor initialization in contract Transfer
?
I am also trying to create a DApp using Truffle with this contract. In this case how can I pass the address of Transfer
contract as parameter to SecondTransfer
contract?