Hi, boys. Assume, that you're writing a staking smart-contract and you want to show your user what tokens he's sent to stake.
User can add or remove from contract any of his tokens.

You could create mapping(address => uint256[]) public userStakedTokens; and keep tracking of users' tokens everytime they call stake or unstake. But if feels not very efficient to me. You always have to manipulate with their arrays.
Maybe it's better to listen smart-contract for events and write what tokens user's has sent to stake into my db? So when I need to show all of them, I'd just make a request to my back-end instead of calling smart-contract?

Aug 23, 2022, 2:56 PM
see popular staking contracts, such as top 10 by TVL
Aug 23, 2022, 3:03 PM

© 2024 Draquery.com All rights reserved.