0

We have a token contract A and an Escrow contract B. While transferring token from an address to contract B we are using transferFrom function which overridden from contract A. But in need to do the transfer , we have to call approve function on contract A. This works if we call the approve function directly from contract A. But if we are overriding the approve function just like transferFrom on contract B, it is failing. Could someone please explain how we can call approve from contract B itself.

  • what do you want to approve?, if you want to approve tokens in the contract b to be moved by someone else, this will work. But if you want to approve tokens of user X to be moved by user Y from contract B this won't work, could you please clarify? – Jaime Jul 5 '18 at 12:00
  • User X have contract A tokens. Using Escrow contract (B) , X wants transfer tokens to either Contract B or User Y. But without calling Approve function from Contract A, this is not working. It works only if the User X , calls the approve function of Contract A directly. We are trying override the approve call inside Contract B and its not working. Is it because, even if the User X calls the approve function from contract B, the msg.sender returned inside the contract A is the contract B address instead of User X address? – Tyson Jul 5 '18 at 12:32
  • why do you need approve or transfers to be done form contact B. If B is an escrow, then users send the tokens to B and then when the conditions are meet, B will send to the users. I think you just need to ask users to send tokens to B and the B do the rest – Jaime Jul 5 '18 at 12:56
  • Escrow Contract (B) has a function transferFrom(address _from, address _to, uint256 _value) which allows us to make the user X send tokens from his address to user Y. We are trying to use it. But when a User X connect it using Web3js, User X has to make call the approve function in Contract A with the token address as param atleast once to allow transfer of the token from User X address to the Escrow contract. – Tyson Jul 6 '18 at 5:55
0

If you want to approve tokens in the contract b to be moved by someone else, this will work. But if you want to approve tokens of user X to be moved by user Y from contract B this won't work. The issue is that calling approve from contract B will have as msg.sender and it will fail.

Hope this helps

0

The rule is: you can approve the future spending of your tokens only. This is assured checking implicitly that msg.sender be the owner of the tokens “approved”.

If Escrow B want to approve something, it can only approve tokens on Escrow B’s account (I.e. owned by the 0x... address at which the Escrow results deployed).

No other possibilities do exist (if we are talking about ERC20).

You should need that a forceTransfer function in the token contract 1) do exists; 2) is accessible by you; in order to be able to do something different.

Any function you write or find written or you design in the Escrow cannot do nothing different from the standard described above, because the tokens reside and are managed in the internal storage of the tokens contract only, by the tokens contract only. Outside of it you can only interact with it, but no tokens exit from their contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.