Is it possible to pack a few transfers of EOS token to different accounts inside of single transaction? I know it's possible to pack multiple arbitrary actions inside one tx, but what about EOS token transfers specifically?

  • What will be your reason for batch transactions? For bitcoin, I understand using batch transactions can save on transaction fees, but since there is no cost to transfer tokens in EOS, you can simply send tokens freely in multiple transactions. Unless you need these transfer actions to be atomic where one transfer fails all fails. – Jeff Zheng Sep 14 at 9:17

In a smart contract, you could do this by emplacing multiple actions into a single transaction, as follows:

transaction transfer;
transfer.actions.emplace_back(eosio::permission_level {_self, N(active) }, N(eosio.token), N(transfer), std::make_tuple(from_account, to_account_1, quantity_to_send, std::string("memo")));
transfer.actions.emplace_back(eosio::permission_level {_self, N(active) }, N(eosio.token), N(transfer), std::make_tuple(from_account, to_account_2, quantity_to_send, std::string("memo")));
transfer.actions.emplace_back(eosio::permission_level {_self, N(active) }, N(eosio.token), N(transfer), std::make_tuple(from_account, to_account_3, quantity_to_send, std::string("memo")));
transfer.send(0, _self, false);

You can do it with cleos by creating the json for each transfer, as follows:

cleos transfer from_account, to_account quantity memo -d -b -s 

This creates json output do this for all the transfers you want to do it for, it should look like this:

{
  "expiration": "2018-10-20T10:54:37",
    "ref_block_num": 92,
    "ref_block_prefix": 276911189,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0040c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

{
  "expiration": "2018-10-20T10:54:42",
    "ref_block_num": 102,
    "ref_block_prefix": 3271438144,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0080c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

{
  "expiration": "2018-10-20T10:54:45",
    "ref_block_num": 109,
    "ref_block_prefix": 718898287,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d00c0c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

To make this into one transaction, copy and paste each of the actions into the first json output, as follows:

{
  "expiration": "2018-10-20T10:54:37",
    "ref_block_num": 92,
    "ref_block_prefix": 276911189,
    "max_net_usage_words": 0,
    "max_cpu_usage_ms": 0,
    "delay_sec": 0,
    "context_free_actions": [],
    "actions": [{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0040c85353840ccd102700000000000004454f5300000000046d656d6f"
    },{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d0080c85353840ccd102700000000000004454f5300000000046d656d6f"
    },{
      "account": "eosio.token",
      "name": "transfer",
      "authorization": [{
        "actor": "fromaccount",
        "permission": "active"
      }
      ],
      "data": "00f2d4142123e95d00c0c85353840ccd102700000000000004454f5300000000046d656d6f"
    }
    ],
    "transaction_extensions": [],
    "signatures": [],
    "context_free_data": []
}

Finally, save this json file, and execute it as follows:

cleos push transaction eosio.token transfer my_json_file.json

You need to make different token contract for that which accepts more than one receivers and only one sender

For example current transfer function is

                        transfer(account_name from,
                        account_name to,
                        asset        quantity,
                        string       memo ) 

You need to modify that function like

                    transfer(account_name from,
                    account_name to1,
                    account_name to2,
                    .
                    .
                    .
                    account_name ton,
                    asset        quantity,
                    string       memo )

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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