I am using an ERC20 token which is used by a smart contact, EOAs also holds tokens

How can I use the transfer function for transferring tokens from the EOA to a different Smart Contract address .

when I use the function transfer within the contract which is to be funded from an account which calls the parent function,

can it be done like this ? tokenContractInstance.transfer(address(this), _bidValue); will the tokens be debited from the msg.sender of the parent function ?

Thank You

  • 1
    If the contract calls transfer, then the tokens will be transferred from the contract. I think you're looking for approve (called by the token owner) and then transferFrom (called by the contract). – smarx Jan 21 at 23:28
  • Yeah got it , I was thinking that , if the msg.sender of the parent function gets delighted call to the transfer func . Got it now , Thanks a lot – CryptoScroller Jan 21 at 23:31
  • How to call approve on behalf token owner when you are inside the contract to which you are sending the contract. Suppose EOA wants to approve the contract, Inside a function can the EOA call tokenInstance.approve(address(this), _tokenAmount) , will this function be called on behalf of msg.sender(EOA) or the smart contract calling the function? – CryptoScroller Jan 25 at 6:33
  • 1
    If that code is in the contract, then it's the contract doing the approving. You need the EOA to call approve on the token contract. – smarx Jan 25 at 6:50
  • can you guide me how to do that with an example? It will be very helpful – CryptoScroller Jan 25 at 12:43

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.