transferFrom method from ERC20 contract interface:

function transferFrom(address _from, address _to, uint _value) public;

transferFrom function from my contract :

function transferFrom(address _from, address _to, uint _value) public returns (bool) {
  token.transferFrom(_from, _to, _value);
  return true;

transferFromOneToMany function with for loop transferFrom function

function transferFromOneToMany(address _from, address[] memory _receivers, uint[] memory _values) public onlyOwner returns (bool) {
  require(_receivers.length == _values.length && _receivers.length >= 1);
  for (uint j = 0; j < _receivers.length; j++) {
    token.transferFrom(_from, _receivers[j], _values[j]);
  return true;

transferFrom function working good, I received confirmation of the transaction ( event Transfer )

transferFromOneToMany doesn't working good, I received success but transaction don't have events of transfer e.g 0x501d19e013defcc6cc1808f75ea0cca575ab8bfb26d96a1869b4671da743e44b

  • 1
    but transaction don't have events of transfer - how exactly have you concluded that? (etherscan wouldn't show you events in either case AFAIK). Commented Apr 7, 2020 at 11:31
  • etherscan.io/tx/… for example this is correct transaction - I have the event logs tab with 2 transfer event Commented Apr 7, 2020 at 11:39
  • I believe that's just a limitation of etherscan, since these events are emitted from the same contract that you send your transaction to (an ERC20 Token contract), while in the other case, you send the transaction to your own contract which doesn't emit any events directly. Commented Apr 7, 2020 at 11:50
  • But the real problem is that funds are not transferred from one account to another. Further more now when I added transferFromOneToMany() function to contract, transferFrom() function was failed with error : Bad instruction e.g. etherscan.io/tx/… Code of contract : pastebin.com/bwr8TiBJ Commented Apr 7, 2020 at 11:59
  • Could you show what token is and how token.transferFrom(_from, _to, _value) is implemented? Commented Apr 7, 2020 at 12:04

1 Answer 1


There are at least two major problems with your code that could explain why it doesn't work, but to now it for sure, I need source code of the smart contract referred by the token variable. Here are the problems:

  1. You ignore value returned by token.transferFrom function. It is possible that the returned value if false in some cases, which means failed transfer.

  2. Your transferFrom function does not have any access control, which means that anybody may call it at steal the tokens.

While the second problem cannot lead to a failed transfer by itself, it makes me think that you misunderstand how transferFrom function is working. Here is the scenario:

  1. Alice calls transferFrom on your smart contract asking it to transfer some tokens from Bob to Carol.
  2. Your smart contract calls token smart contract asking it to transfer tokens from Bob to Carol.
  3. For token smart contract this call is not related to Alice in any way, as the call is originated from your smart contract, not from Alice's address.
  4. Token smart contract ensures, that Bob allowed your smart contract to take Bob's tokens.
  5. Token smart contract transfer tokens from Bob to Carol.
  6. Token smart contract reduces the number of tokens your smart contract is allowed to take from Bob.

I assume that at steps 4 and 6, there should be Alice instead of your smart contract, for the whole schema to work properly. In current implementation, anybody may call transferFrom function of your smart contract asking to transfer Bob's token to arbitrary address, and, as Alice's address is never validated, the tokens will effectively be stolen.

So, failed transfer in your case may be caused by the fact that Bob allows Alice to take his tokens, while token smart contract checks whether Bob allowed your smart contract to take them.

OK. I looked into your transaction and it seems that you've passed the following values to transferFromOneToMany:

_from: 0x18c7abf493c747f39ce006abeb9bd6d2592e833e
_receivers: [
_values: [949999, 50000]

Address of your contract is 0x14a108a349cde4cb9019672f2489b003dc393049. Addres of token smart contract is 0xdAC17F958D2ee523a2206206994597C13D831ec7 You've sent transaction from the following address: 0x11b202de5b68ea66610b571b028dcca7743b64bc and this address is the owner of your smart contract.

So, for your transfers to succeed, the owner of _from address should have allowed your smart contract to take at least 999999 tokens. However, actual allowance for _owner: 0x18c7abf493c747f39ce006abeb9bd6d2592e833e and _spender: 0x14a108a349cde4cb9019672f2489b003dc393049 is zero. This is why your transfers fail.

  • Please check out the contract that this dude is using, following this transaction, which he posted in a comment to his previous question. This contract uses a non-ERC20-standard token (deployed a while ago), which does not return anything in its transfer, transferFrom and approve functions. Subsequently, this user cannot rely on the returned values of these functions. Commented Apr 7, 2020 at 12:48
  • His token variable relies on an interface, in which these functions aren't returning anything. Commented Apr 7, 2020 at 12:49
  • This does not mean, that real token smart contract, referred by the token variable don't return anything. I would prefer to look at its source code. Commented Apr 7, 2020 at 12:51
  • Here is his previous question. Here is the specific transaction mentioned in a comment to that question. Here is his contract used in that transaction. And here is the token used in that contract. Commented Apr 7, 2020 at 12:52
  • You can check out this token and see for yourself. Commented Apr 7, 2020 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.