5

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 '18 at 9:17
4

Smart Contract Method

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);

Cleos Method

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
  • Hi Phillip Mr Y How can we split the 1 EOS in n accounts – Carlos Mar 31 at 19:48
  • This question has been answered. Please ask a new question for advice on splitting 1 EOS into N accounts – Phillip Hamnett - EOS42 Apr 1 at 11:59
1

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 )
  • do they occur parallely or sequencly ? – Nirdesh Kumar Choudhary Dec 27 '18 at 9:27
  • 1
    sorry, but i have not analyzed that behavior of my code... – Mr.Y Dec 27 '18 at 9:49
0

If you use python, you can try this code transactions

from ut import runcleos
import json


def _push_transaction(d):
    cmd = [
        "cleos",
        "-u",
        "https://api.eosbeijing.one",
        "push",
        "transaction",
        json.dumps(d),
    ]
    return runcleos(cmd)


def getaction(contract, action, data, f, p=False):
    """
    contract :要玩的合约地址
    action: 玩的方法
    data : 详细信息
    f :账号
    """
    cmd = [
        "cleos",
        "push",
        "action",
        contract,
        action,
        json.dumps(data),
        "-d",
        "-s",
        "-p",
        f,
    ]
    return json.loads(runcleos(cmd))


def push_transaction(actions):
    """
    actions是 由多个action组成
    每个action由 [合约账号,调用方法,调用参数,签名者] 组成
    """
    # actions = [
    #     ["eosio.token","transfer",["eosbocaira12", "redredredred", "1.0000 EOS", "save"],"eosbocaira12"],
    #     ["eosio.token","transfer",["eosbocaira12", "redredredred", "1.0000 EOS", "save"],"eosbocaira12"],
    #     ["eosio.token","transfer",["eosbocaira12", "redredredred", "1.0000 EOS", "save"],"eosbocaira12"],
    # ]
    for i in range(len(actions)):
        action = getaction(*actions[i])
        if i == 0:
            ret = action
        else:
            ret["actions"].extend(action["actions"])
    return _push_transaction(ret)


if __name__ == "__main__":
    actions = [
        [
            "eosio.token",
            "transfer",
            ["eosbocaira12", "redredredred", "1.0000 EOS", "save"],
            "eosbocaira12",
        ],
        [
            "eosio.token",
            "transfer",
            ["eosbocaira12", "redredredred", "1.0000 EOS", "save"],
            "eosbocaira12",
        ],
        [
            "eosio.token",
            "transfer",
            ["eosbocaira12", "redredredred", "1.0000 EOS", "save"],
            "eosbocaira12",
        ],
    ]
    print(push_transaction(actions))

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.