We are designing a blockchain game, currently we have encountered some challenges in the wallet and interaction with the smart contract and token transfer that I would like to consult you about.
First part: making and managing the wallet
The game has an internal wallet, in fact, if I want to explain the whole boter, when the user registers in the game, a request to create a wallet is sent to the API of the project, which plays the role of the interface between the user and Web 3, like this The CreateWallet function is called in the API and randomly generates a GUID called recovery ID and uses this ID to create a wallet, then returns the recovery ID along with the private key and wallet address to the user. The recovery ID is shown to the user only once and the user is told to save it in a safe place and be diligent in protecting it, from this ID to recover the wallet when the user deletes the history of his device or the game from It is used to delete on his mobile phone
Our first challenge in this section is whether this method is optimal for making an in-game wallet or not? Our second challenge is how to store the private key, should we store the private key in the user's phone or in the database? Our third challenge in this section is what encryption algorithm to use for private key encryption and what parameters to use for encryption key and IV values?
In addition, I would like to point out that because the game users are generally not familiar with the blockchain world, that is why we want to use the internal wallet so that the users do not get involved in creating an external wallet and connecting it to the game in order to avoid the complexities of this task. to give a better experience to the game user.
Second part: Transaction fees
Due to the fact that almost any interaction with the blockchain in a way that has an impact on the blockchain requires payment of a fee, because the game and its smart contracts are based on the BNB smart chain, users must charge their wallets with BNB currency to be able to spend pay their fees,
The first challenge of this section is whether it makes sense for blockchain games that users pay their own fees or should the company pay the fees?
What if the user does not have enough BNB to pay the fee? Should we show an error to the user to increase his BNB balance or in this case, the company should pay the fee?
And the last challenge of this section is whether to embed a button in the game through which the user can withdraw all his BNB balance and transfer it to another wallet. There is no a balance to pay the fee, is it reasonable to reduce the estimated amount of gas from the balance amount and transfer the remaining amount so that the fee can be paid? In this case, some BNB currency will be blocked forever in the wallet, is this method reasonable?
Third part: How to pay for gas by the company
If the best decision for all transactions, or in certain cases such as when the user does not have enough balance to pay the transaction fee, is for the company to bear the cost of gas, how should this be done?
The solution that comes to my mind is to ask the user to allow the company's smart contract or wallet to execute some transactions and transfers on behalf of the user after the user is registered and after the wallet is created.
In this method, the user must transfer some BNB currency to his own wallet, then the Approve function in the smart contract is called to allow the smart contract or company wallet to perform transactions on behalf of the user and use BNB currency for payment. Approve transaction gas is used.
In this case, for all transactions or in some cases, the company's smart contract or wallet will mediate the execution of transactions, and the cost of gas will be deducted from the company's BNB balance. Is this method reasonable?
The challenge of this method is that the cost of gas may be more than the balance of the company's wallet or smart contract, what should be done in this case?
Or if we want to use the smart contract as an intermediary for gas payment, it is not possible to deposit BNB currency into the smart contract, what should be done in this case?
I would like to thank my dear friends who guide me, to be honest, I already had experience in DApp development, but I have no experience in making wallets and GameFi development, that's why I ask so many questions about this.
Thank you very much for your help ...