I have following contract here on ropsten https://ropsten.etherscan.io/address/0x813870feba76f27ec1afcf79432e065a4839f7ab#code

I want to use tokens from a different erc20 contract(0x8eB24319393716668D768dCEC29356ae9CfFe285) inside my own contract.

I know that i have to approve the amount i want to use in my own contract from the Token contract those tokens i want to use in my contract (0x8eB24319393716668D768dCEC29356ae9CfFe285).

What i did In remix i compiled the code and selected TOKEN from inside my contract, i deployed TOKEN "at address" of 0x8eb24319393716668d768dcec29356ae9cffe285

i than approved this address 0x813870feba76f27ec1AfcF79432e065A4839F7(my contract)

and set amount to approve to 2 Which all worked. enter image description here

But when i try to use the buy Function from inside my code- the transaction fails.

How can i use Token from a different erc20 Contract in my Contract?

  • Now how exactly does the title of your question represent anything of what you're asking in the body of your question??? Jan 15, 2020 at 14:03
  • its only 1 half of the question iits not working i still cant use the buy function- the whole thing is only finished when those 2 contracts work together
    – yappy twan
    Jan 15, 2020 at 14:08
  • i obviously messed something up thatswhy im asking how to do this the proper way
    – yappy twan
    Jan 15, 2020 at 14:09
  • 1
    @goodvibration already changed it:)
    – yappy twan
    Jan 15, 2020 at 14:26

1 Answer 1


So taking a look at the events on etherscan, it looks like Approval events have been submitted to approve the transfer of 2 tokens from

0x62f28320f688a7a4e0021c55d7ffd1acd770a133 (your wallet?)


0x813870feba76f27ec1afcf79432e065a4839f7ab (your contract)

enter image description here

However I wrote a small contract to check the balances and allowances in the ERC20 contract you are working with. The balance of your wallet 0x62f28320f688a7a4e0021c55d7ffd1acd770a133 in this ERC20 token contract is 0. I believe this is why the transfer is failing. You've approved the transfer of tokens to your contract, but the address you are trying to transfer tokens from does not have any.

enter image description here

Updating With Comment Answers

Additionally, the msg.sender in the buy function needed to be listed as an ambassador.

  • You can see on etherescn that i have 10 AGI in my wallet ropsten.etherscan.io/address/… But you are correct when i check my metamsk account it says 0 agi
    – yappy twan
    Jan 15, 2020 at 15:01
  • Yes, but the address of AGI is 0xb97e9bbb6fd49865709d3f1576e8506ad640a13b not 0x8eB24319393716668D768dCEC29356ae9CfFe285 the address your are interacting with when you create your erc20 contract and try to make the transfer
    – Steven V
    Jan 15, 2020 at 15:04
  • i tried the same steps with this address 0xb97e9bbb6fd49865709d3f1576e8506ad640a13b and its also not working
    – yappy twan
    Jan 15, 2020 at 15:09
  • the transfer function works but i still cant use the buyfunction
    – yappy twan
    Jan 15, 2020 at 15:24
  • 1
    thanks to your help of course ;) or I would still be stuck?
    – yappy twan
    Jan 15, 2020 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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