1

I was reading this contract https://docs.soliditylang.org/en/develop/solidity-by-example.html#safe-remote-purchase that I found in the solidity documentation and I assume this contract is unique and deployed by the auction house. All users can make an offer. From an implementation point of view, how does a user in web3.js call the methods of this contract if he didn't deploy it?

1 Answer 1

1

By reading at the contract, there are essentially two roles:

> Seller: this is assigned inside the constructor, meaning that only the person who deployed this contract becomes a seller:

constructor() payable {
    seller = payable(msg.sender); // Contract creator becomes seller
    value = msg.value / 2;
    require((2 * value) == msg.value, "Value has to be even.");
}

> Buyer: it can be anyone who performs a purchase, as described in the function below:

function confirmPurchase()
    public
    inState(State.Created)
    condition(msg.value == (2 * value))
    payable
{
    emit PurchaseConfirmed();
    buyer = payable(msg.sender); // Anyone -successfully- calling this function becomes buyer
    state = State.Locked;
}

Once the roles are assigned, there are other functions within the contract that can be called only by the seller or buyer depending on the function modifiers (onlyBuyer, onlySeller).

7
  • thanks I want to ask you one last question. In this smart contract link who calls the reveal function?
    – EMANUEL
    Commented Feb 7, 2021 at 7:23
  • Anyone can call this function as long as the bidding process has ended (onlyAfter(biddingEnd)) and during the reveal period (onlyBefore(revealEnd)). This is a commit-reveal scheme. Commented Feb 7, 2021 at 8:31
  • but is it possible to build a mechanism to call this method automatically at the end of the auction period?
    – EMANUEL
    Commented Feb 7, 2021 at 8:55
  • 1
    Not from the smart contract directly, but you can call that method externally. If you know the end date in advance, you can have a process to call that function right at the end of the auction, or you can have a process to call the method every N minutes or hours. In essence, you need to manage that externally, but there are many different ways. Commented Feb 7, 2021 at 9:08
  • thanks I meant just that. The only way I have found is to use an alarm but I am not convinced. I am working with ethereum and web3.js for the first time so I don't have much knowledge. Could you recommend me a way to do this process automatically please?
    – EMANUEL
    Commented Feb 7, 2021 at 9:17

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.