My apologies in advance for this noob question, I think a scenario might be the best way to ask:

I have a simple escrow smart contract that facilitates the buying of products. For simplicity sake, the contract is deployed at 0x01... and has 3 methods:

deposit() payable - buyer only

shippedItem() - seller only

finalize() - buyer only

and a simple web interface acting as an online store.

User 1 comes to the store and buys product by depositing in the smart contract. The seller marks the item shipped and the deployed contract state becomes 'awaiting finalization'.

User 2 comes to the store and buys product by...Im not 100% sure how? Would a new contract need to be deployed for this user? Or is there a way to instead have contract 'instances' that could be created and interact as independent objects? Ex:

--> Deployed contract at 0x01...

         --> Instance 1   State: awaiting finalization
         --> Instance 2   State: awaiting deposit 

I did see a question similar to this that said you could use what are called libraries to get this kind of behavior, but I'm still unsure if contract libraries fit this scenario. I ask this because from a practical business standpoint, having the buyer or seller deploy a new contract each time does seem like it could end up being quite expensive on the mainnet. Thanks for viewing my question.

1 Answer 1


I think this is better handle with better contract design. Instead of handling buy/sell transaction variables one-by-one, you can have a struct defining an escrow transaction. Something like:

struct escrowTx {
  uint256 TransactionID;
  address Seller;
  address Buyer;
  bool Executed;

Then each escrow transaction is just a new instance of this object and the smart contract manages it through its lifecycle. Then only one contract is needed.

  • after some research this indeed seems to be the right approach, thanks!
    – guest
    Sep 21, 2021 at 5:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.