Search code examples
solana

Entities and Solana accounts


I'm new to Solana/web3 and started learning about developing dApps for Solana. From my understanding, an "account" is essentially just a space allocated in memory in the decentralized "computer".

Does this mean that if I were to write a dApp for a bidding usecase for example, it would involve 1 account for each item being bid out, 1 account for each bidder, and 1 account for each bidder's bid?


Solution

  • You've understood the concept perfectly: account == data. It's all a matter of opinion after that, and you have the same tradeoffs as with any software system design.

    For example, do you want to have one big global state? You could have all the items and their associated bids in one account. That would likely be a huge account that gets changed often, so it could create bottlenecks in the blockchain.

    Then you may think, what about just one account per item being bid on? In that case, you could store all of the bids and bidders for the item in one place. In that case, you may not need 1 account for each bidder and 1 account for each bidder's bid.

    If you go that route, and a user wants to know about all of their bids from the frontend, it may be tough to discover, since you'd have to iterate through all of the items being bid on to see if they have a bid. So in that case, maybe you do want 1 account per bidder.

    So unfortunately, the answer is: it depends!