Reader

Is it possible to design a backend to interact with a smart contract instead of the user?

| Software Engineering Stack Exchange | Default

I'm new to blockchain development and have been studying smart contracts. I have a question regarding transaction execution in a smart contract for an event ticketing platform.

The contract includes functions for purchasing tickets, issuing refunds, and canceling events. There are two possible approaches to handle blockchain interactions:

  • The frontend directly interacts with the smart contract via a user's wallet app.
  • The backend interacts with the blockchain on behalf of users, meaning only the platform's wallet executes transactions.

For example, consider the refundTicket function:

Approach 1:

function refundTicket() public {
    // Refund logic
}

Approach 2:

function refundTicket() public onlyPlatform {
    // Refund logic
}

I'm wondering whether approach 2 is possible and used in other apps. I understand that it introduces a single point of failure if the platform's wallet is compromised, but are there any apps using second approach? Is second approach considered as bad design?

I've seen lots of docs but no clear answer