I know what is tx cost etc. I just interested, is it possible to pay for any transaction not from the initiator balance, but from the contract's balance instead

Aug 2, 2021, 8:07 PM
don't do it imo
anyone can call your contract
a lot of times
and then, you're rekt
Aug 2, 2021, 8:08 PM
yes, no problems
it's testnet )
Aug 2, 2021, 8:08 PM
The caller would need to pay for the gas up front in order to make the call, but you could then reimburse them. So they would need at least some balance.
Aug 2, 2021, 8:08 PM
Is it possible? Just possible, thats all )
Aug 2, 2021, 8:08 PM
uint256 gas = tx.gasPrice * theAverageGasUsed;
payable(_msgSender()).transfer(gas);
Aug 2, 2021, 8:09 PM
got it, thank you. Will look for the info about reimburse
Aug 2, 2021, 8:09 PM
thats the code for it
but you shouldn't do that on mainnet
Aug 2, 2021, 8:10 PM
But I also agree with spaceowl that it might be unsafe.
Aug 2, 2021, 8:10 PM
got this might help
https://solidity-by-example.org/sending-ether/
Aug 2, 2021, 8:11 PM
thank you mate
Aug 2, 2021, 8:13 PM
it's exploitable if the caller manages to call the contract using a gas price lower than the current market price
Aug 2, 2021, 8:22 PM
thanks for pointing this out, this is good information
Aug 2, 2021, 8:23 PM
@anpako probably you might want to look at GSN https://docs.openzeppelin.com/learn/sending-gasless-transactions
Aug 2, 2021, 8:32 PM
👌🏼
Thanks a lot, this is exactly what Im looking for
Aug 2, 2021, 8:42 PM

© 2024 Draquery.com All rights reserved.