betrayal
betrayal

Reputation: 1

Failed Transaction on Ethereum

I've played around for some bit with a selfmade program. I just tried to sell some random token on uniswap which I bought earlier. My transaction somehow didn't go through and I don't know why.

https://etherscan.io/tx/0xcb4ef6baab722e00e6dad75d12398fc88cc5177445758064a14c8433612a860f

Does someone have an Idea why it didn't go through, I'm not familiar enough with the solidity/ethereum yet.

Thanks a lot in advance.

Upvotes: 0

Views: 1180

Answers (1)

Ming
Ming

Reputation: 775

We can check which require the transaction failed to meet by searching for the message in contract TRANSFER_FROM_FAILED.

The function calls transferFrom function. transferFrom function requires the owner of the token to approve a spender to spend on his/her behalf.

Seems like you have not approve the spender to spend on your behalf.

You can check more info regarding transferFrom at this docs

// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');

swapExactTokensForETH uses safeTransferFrom function

...
TransferHelper.safeTransferFrom( 
   path[0], 
   msg.sender, 
   UniswapV2Library.pairFor(factory, path[0], path[1]),
    amounts[0]
);
...

Upvotes: 2

Related Questions