# Is it possible/safe to use .call for ERC20 token transfer?

**URL:** <https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376>\
**Category:** Smart Contracts\
**Tags:** erc20\
**Created:** [October 10, 2022, 9:02am UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376 "2022-10-10T09:02:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliashezron](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/eliashezron/32/15447_2.png) [@eliashezron](https://forum.openzeppelin.com/u/eliashezron)\
**Post date:** [October 10, 2022, 9:02am UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/1 "2022-10-10T09:02:39Z")

</div>

out of curiosity, is it possible to use **call** for ERC20 token transfer? I always use **transfer** for ERC20 tokens and call for eth. on the native token depending on the evm chain.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [October 10, 2022, 11:03am UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/2 "2022-10-10T11:03:49Z")

</div>

I think yes, but you need to pass encoded data to do this, and maybe it is `send`, I think `call` is a getter function.

---

<div class="post-metadata">

**Author:** ![eliashezron](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/eliashezron/32/15447_2.png) [@eliashezron](https://forum.openzeppelin.com/u/eliashezron)\
**Post date:** [October 10, 2022, 11:11am UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/3 "2022-10-10T11:11:45Z")

</div>

This is what I meant.

this (`IERC20(_token).transfer(_withdrawerAddress, _amount`) vs `(bool sent, ) = _to.call{value:_value}('')`

what is the best way of transferring an ERC20 token?

for reference, you can look at this [example](https://solidity-by-example.org/sending-ether/) in solidity by example.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [October 10, 2022, 11:16am UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/4 "2022-10-10T11:16:14Z")

</div>

Ohhh, you mean in the contract rather than `web3.js`.

Yes, you can. But you need to pass data, such as `(bool sent, ) = _to.call{value: value}(data);`

---

<div class="post-metadata">

**Author:** ![eliashezron](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/eliashezron/32/15447_2.png) [@eliashezron](https://forum.openzeppelin.com/u/eliashezron)\
**Post date:** [October 10, 2022, 11:22am UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/5 "2022-10-10T11:22:06Z")

</div>

So, what method is recommended for ERC20 token transfers? `transfer` or `call`

---

<div class="post-metadata">

**Author:** ![helio.rosa](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/helio.rosa/32/15562_2.png) [@helio.rosa](https://forum.openzeppelin.com/u/helio.rosa)\
**Post date:** [October 10, 2022, 12:33pm UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/6 "2022-10-10T12:33:27Z")

</div>

The syntax `something.call{value: val}(data)` only transfers eth, not ERC20 tokens. to transfer tokens as @Skyge said, you need to format the data to include the amount (this is what calling `transfer()` does).

---

<div class="post-metadata">

**Author:** ![eliashezron](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/eliashezron/32/15447_2.png) [@eliashezron](https://forum.openzeppelin.com/u/eliashezron)\
**Post date:** [October 10, 2022, 1:44pm UTC](https://forum.openzeppelin.com/t/is-it-possible-safe-to-use-call-for-erc20-token-transfer/32376/7 "2022-10-10T13:44:09Z")

</div>

thank you @helio.rosa
