How transferFrom can be used with addresses other than the contract’s own?

This is a great article (Example on how to use ERC20 token in another contract) thank you, really clear.

However I am still struggling to understand how transferFrom can be used with addresses other than the contract’s own. For instance let’s say I hardcode an address at this line:

_token.transferFrom(from, 0x281Dc55606849A9BC00CeA79E2d657fCE6756A30, 1000);

I approve that address on truffle console:

token.increaseAllowance("0x281Dc55606849A9BC00CeA79E2d657fCE6756A30", 1000)

But still I get the “ERC20: transfer amount exceeds allowance” error. I also get this error if I pass the address as an argument rather than hard code. Not exactly sure what mistake I am making here?

1 Like

Ok, sorry I’ve figured this out, but will add my solution in case others find it.

My problem was I should have been increasing the allowance for the contract, not the address that is actually receiving the token. So if you add a different receipt address in the transferFrom method (as in my above example) you continue to use:

token.increaseAllowance(receiver.address, 1000) 

as it is the contract you are increasing the allowance of, not the address you ultimately send the money too! Thanks again for a great article.

1 Like

Hi @PreciousChicken,

Welcome to the community :wave:

Glad you were able to resolve. Please ask all the questions that you need.

1 Like