Hi, I am pretty new to blockchain technology, and I had an idea that it would be nice if clients had to pay fees to use a server api or website. But I have a hard time figuring out how this should be implemented in detail, so I am asking here if someone could help me.
The idea is to have a server expose an API, that is guarded by a fee collector, i.e. the server has a wallet and clients have to pay a fee to that wallet before their requests get accepted. This should also work for websockets, where each processed message sent between client and server should incur a fee.
The client should be able to use a browser wallet to automatically pay the fee while using the website without any interaction (if configured) and with as little overhead as possible.
I imagine this to be implemented in a way as the server sending clients it’s wallet address and something like a catalogue, so that clients know how to pay the fees before they make the requests. Basically accessing something like a catalogue route or the index of a website is free and when the user initiates a chargable request, they send a proof that they paid the required fee along with it. The server then verifies the proof and processes the request or rejects it.
For websockets this might be a bit more complicated, because the client would need to pay for subscriptions which are executed by the server, so the client needs to deposit funds in advance which are then used to pay the fees directly on the server. The server could send “low balance” notifications over the websocket to inform the user if they need to deposit more funds to use the service.
Here I am a bit unsure how to implement this properly. Clients could pay a few messages in advance and trust the server to send them their remaining balance back when the websocket closes, but that requires trust and incurs a second transaction fee on the solana blockchain for every closing websocket. Another option would be to manage a user account on the server where users can control how they move funds in and out. That might require too much maintenance for some users though.
The ideal way I would like would be a client wallet that can execute transactions on a third, authorized parties request. So that the client can give the server the permission to withdraw exactly the fees from their wallet when they require it.
Maybe we need an on-chain program owned wallet, which has an owner (the client) who can allow specific services to collect fees from that account to their accounts. The owner would authorize specifc services to request a transaction to their account, and the wallet would schedule a transaction when an authorized service requests it. This would however require an on-chain program account for each client, which the client or the service has to pay rent for.
Could someone who is experienced with Solana and on-chain programs give me some feedback to this chain of thought? Am I misunderstanding something or am I missing some simpler solution to these problems? It would very much help me understand Solana better.