0

I am trying to run this buyer seller contract in truffle using testrpc. I am unable to assign the address and value for seller at the time of deploying contract. Here is my solidity code and deploy.js code

contract Purchase {
  uint public amount;
  address public seller;
  address public buyer;

  function Purchase(address addr, uint _amount) {
    seller = addr;
    amount = _amount;
  }

  function confirmPurchase(address _buyer, uint val) {
    buyer = _buyer;
    if ( val == amount) {
      buyer.transfer(amount);
      seller.transfer(this.balance);
      seller.balance;
    }
  }

  function getBalance() returns (uint balance) {
    return seller.balance;
  }

  function getAddr() returns (address) {
    return msg.sender;

  }
}

Deploy.js code:

var Purchase = artifacts.require("./Purchase.sol");
module.exports = function(deployer) {
 deployer.deploy(Purchase,"0x13ac3e54b3d46757b6534e8b1c068caadb88da4a", 10);
};
0

Try this:

pragma solidity ^0.4.11;

contract Purchase {
  uint public amount;
  address public seller;
  address public buyer;

  event LogPurchase(address buyer, uint amount);

  function Purchase(uint _amount) {
    seller = msg.sender;
    amount = _amount;
  }

  function confirmPurchase() 
    payable // payable so it accepts value: from sender
    returns(bool success)
  { 
    if(msg.value != amount) throw; 
    LogPurchase(msg.sender,msg.value);
    seller.transfer(msg.value); // sends the funds to the seller
    return true;
  }
}

It's just a nudge to help unstuck you, not a fully viable solution you would rush into production.

When you deploy the contract, drop the address because it figures it out for you.

var Purchase = artifacts.require("./Purchase.sol");
module.exports = function(deployer) {
 deployer.deploy(Purchase, 10);
};

Hope it helps.

  • When we are deploying the contract with truffle in testrpc the contract must deploy in any of the 10 testrpc accounts which are available is that correct? – Jazz Jul 3 '17 at 17:34
  • It will default to deployed from the first testrpc account and that account will be the owner. – Rob Hitchens - B9lab Jul 3 '17 at 17:44
  • But for me the contract deployed address is not matching with any of the given testrpc accounts – Jazz Jul 4 '17 at 7:38
  • It is "from:" one of your accounts, but every contract has it's own unique address. It's not IN the user account, it's BY the user account. – Rob Hitchens - B9lab Jul 4 '17 at 13:43

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.