1

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?

  • @ Rob Hitchens How can i solve these issues – Crissi Mariam Robert Jan 10 '17 at 10:04
  • Please, try not to ask multiple questions in one post. Also, it might be useful to include which VMException you get. – Afr Jan 10 '17 at 10:53
  • @ 5chdn Jump Exception – Crissi Mariam Robert Jan 10 '17 at 11:39
  • @5chdn I am using truffle framework for contract creation.How can i pass the address of 'Transfer' contract as parameter to 'Second Transfer' contract? – Crissi Mariam Robert Jan 10 '17 at 11:41
1

I've tried your code it works without exception, i think you passed a wrong contract address.

enter image description here

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.