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

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.

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.

This is what I meant.

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

what is the best way of transferring an ERC20 token?

for reference, you can look at this example in solidity by example.

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

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

1 Like

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

The syntax{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).


thank you @helio.rosa