0

I am developing a Dapp in which users can buy and sell stamps. I have two different smart contract with the following struct each (plus setter/getter functions):

 //Stamp.sol
 struct Stamp {
    bytes32 id;    //id generated by keccak
    bytes32 name;    //name of the stamp
    uint cost;     //cost in wei of buying the stamp
    address owner; //owner of the stamp
}

//Envelope.sol
struct Envelope {
    bytes32 id;    //id generated by keccak
    string color;  //color of the envelope
    uint cost;     //cost in wei of buying the envelope
    address owner; //owner of the envelope
}

A user can buy a stamp/envelope or sell a stamp/envelope that she owns.

I assume that each user stores her stamps/envelopes on a DB and in my frontend I read the DB and I create a new struct of the corresponding object in the contract. This means that a stamp owner can be different from an envelope owner.

The users can view the available stamps/envelopes but they have to buy a pair (stamp/envelope) of the available items each time.

In order to handle the payment, my idea is to have a different contract that handles the payments, which has a function execPayment with the following arguments:

1) ID of the bought stamp

2) ID of the bought envelope

3) Address of the Envelope.sol

4) Address of the Stamp.sol

So when I call the execPayment method, the contract will retrieve the relevant information for each item based on the ID and find the cost and the owner, and then transfer the amount to the right address.

What is the best/efficient way to design the contract for payments?

I also don't know how to transfer the money from the seller since there is one buyer but 2 (possibly different) sellers who get different amount of money.

4
  • I see a very big problem with your method: The sender of the transaction (the guy who buys) does not know how much ether to send. However, this needs to be known when sending the transaction to buy. Apr 3, 2018 at 6:04
  • In my code I call the smart contract method using the value property of solidity for transferring funds to the contract so the user can see in metamask before signing the transaction how much ether she'll pay. Or you mean sth else?
    – bunjee
    Apr 3, 2018 at 8:33
  • Nono, that's what I meant Apr 3, 2018 at 9:47
  • Then that's not a problem I think..
    – bunjee
    Apr 3, 2018 at 18:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.