2

How can I add to a payable function the possibility for the buyer (a company, in my case) to add some details about itself at the moment of performing the payment (e.g. registered number and company name)?

Below is the code that I'd need to modify to add the above mentioned :

contract KYCPurchase {
  uint public price = 2 ether;
  address[] public buyer;

  function buy() public payable {
    require(msg.value >= price);

    // Keep a list of buyers who have transferred enough ether
    buyer.push(msg.sender);

  }

Thanks!

1

It is important to note that payable functions need not have zero arity.

You can simply rewrite your contract like this:

pragma solidity ^0.4.24;

contract KYCPurchase {
  uint public price = 2 ether;

  struct Company {
      string registeredNumber;
      string name;
  }
  mapping (address => Company) companies;

  function buy(string registeredNumber, string name) public payable {
    require(msg.value >= price);

    // Keep a list of buyers who have transferred enough ether
    companies[msg.sender] = Company(registeredNumber, name);
  }
}

I made the registeredNumber a string because it's more inclusive - in some jurisdictions they can also contain letters - but feel free to switch it to an uint256 or whatever you need

  • Thanks a lot Paul. Would you by any chance know how the owner of the contract who received the payment could check if the payment has been done by a specify Company "XYZ Limited", eventually looking up and checking by their e-wallet address? – Marialuisa Marchese Nov 22 '18 at 21:40
  • I tried with the following function but it does not work: function isKYCPaymentOK (address Company, string registeredNumber, string companyName) onlyOwner public { public view returns (bool ok) } – Marialuisa Marchese Nov 22 '18 at 22:01
  • @MarialuisaMarchese Please ask a new question on StackExchange, it's hard to investigate here. – Paul Berg Nov 22 '18 at 22:26

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.