0

Hi I'm trying to call transfer and transferFrom on the Tether smart-contact token located at 0xdAC17F958D2ee523a2206206994597C13D831ec7.

It is the only token I have a problem with transferring from within my smart-contract.

I'm guessing it's because of the use of the onlyPayloadSize modifier. If anyone understands whats going on, and how to fix this, that would be awesome.

4
  • what is the issue?
    – Jaime
    Dec 23 '18 at 17:22
  • onlyPayloadSize should cause problems only if you're trying to invoke this function dynamically from another contract (i.e., via call). Dec 23 '18 at 21:43
  • How do you invoke transfer or transferFrom? Do you have a transaction that failed?
    – Ismael
    Dec 24 '18 at 14:59
  • I am invoking the transfer and transferFrom function from within my smart-contract. So i'm using another smart-contract to invoke it.
    – GK1
    Jan 4 '19 at 23:12
1

This answer is 2 years late.. but I ran into this exact same problem today, and it surprised me how little information I could find.

The problem is that, calling usdt.transferFrom works with an external account, but does not work when calling from within a contract.

USDT did publish its contract code : https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#code

Which shows it uses the onlyPayloadSize modifier. According to another answer here: Validating msg.data.length and the article it references: https://blog.coinfabrik.com/smart-contract-short-address-attack-mitigation-failure/

It is possible for EVM to pad calls, causing msg.data.length to be longer than expected, thus failing the tx.

The most common solution seems to be just using Zeppelin's SafeERC20 library, like here in Aave's LendingPoolCore.sol, which passes arguments to transferFrom via abi.encodeWithSelector(token.transferFrom.selector, from, to, value)

I tried it and it works perfectly. It costs a little bit more gas, my estimate is 20k-40k more, not a significant amount.

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.