i am able to send eth (with a payable function ) to the my contract but what i really need is that when the user interact with the contract it takes a specific amount on the msg sender and add it to its balance.
Asked
Active
Viewed 194 times
0
-
A contract cannot withdraw ether from other addresses. It can only withdraw from its own balance. You can achieve something similar using ERC20 function transferFrom. See this answer https://ethereum.stackexchange.com/a/46458/ to learn how to use it. – Ismael May 17 '22 at 06:58
1 Answers
1
The sender must attach the required amount of ETH to the transaction.
mywallet.sendTransaction({to: contractAddress, value: "1000000000"})
Contract will then be receiving this amount as part of the transaction.
Kof
- 2,954
- 6
- 23
-
so if i understand i do
msg.sender.sendTransaction({to: contractAddress, value: "1000000000"})do i need to import any library for this function sendTransaction ? – dev May 16 '22 at 07:21 -
-