0

I'm currently trying to get my contract Guess own another contract, MetaCoin, so that it initializes with 10k MetaCoin.

Here is the MetaCoin contract:

contract MetaCoin {
 address owner;

 mapping (address => uint) balances;

 event Transfer(address indexed _from, address indexed _to, uint256 _value);

 function MetaCoin(address caller) {
      owner = caller;
      balances[msg.sender] = 10000; //Although this uses msg.sender, I've tried using owner and caller as the arg as well.
 }

 function coinsOwned() returns(uint){
      return balances[this];
 }

 function getOwner() returns(address){
      return owner;
 }

 function sendCoin(address receiver, uint amount) returns(bool sufficient) {
      if (balances[msg.sender] < amount) return false;
      balances[msg.sender] -= amount;
      balances[receiver] += amount;
      Transfer(msg.sender, receiver, amount);
      return true;
 }

 function getBalance(address addr) returns(uint) {
      return balances[addr];
 }

}

The owner is properly initialized (getOwner correctly returns Guess's address), but the balance is not. I'm unsure on what the issue is, whether it's the constructor, or the way I'm deploying it through truffle. I don't believe that the coin is being sent to another account, because none of the accounts generated by testrpc have the 10k, and neither Guess nor MetaCoin own the coin either. Does anyone know what's happening?

Here is my deploy code as well (using Truffle)

module.exports = function(deployer) {
  deployer.deploy(Guess).then(function(){
    return deployer.deploy(MetaCoin, Guess.address);
  });
};

The contract Guess is essentially blank, with a no arg constructor that doesn't do anything.

0

You have to pass the instance.

module.exports = function(deployer) {
  deployer.deploy(Guess).then(function(instance){
    return deployer.deploy(MetaCoin, Guess.address);
  });
}; 

Have fun.

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.