Solidity Gas Fees – How to Cover Gas Fees in ERC20 Transactions

erc-20gas-pricesolidity

I want to create a solidity smart contract (ERC20) for a play to earn and I would like to know how to reward the winners without them having to pay gas fees when they claim their winnings.

I think that's not possible but I need confirmation.

The rules of my game are very simple:

  1. Player A and Player B deposit on the smart contract the same amount.
    Example: each player deposits 1 ETH
  2. The winner gets the amount deposited (2 ETH)

Is it possible to allow the winner to recover his winnings for free. That is to say that the gas fees of the transaction are taken into account by another entity (ex: the owner of the contract)?

(Or do you have any suggestions?)

Best Regard and Thank you

Best Answer

Yes you can. Not sure what is the logic of your game but let's say once they deposit the 1ETH, you save their addresses in the contract. You can get the user's address with msg.sender.

Once the game is finished, you can just transfer the prize to the winner using address.call.value(amount)( ).

Related Topic