1

I tried to create a function to transfer multiple tokens on one transaction.

code.

token.cpp

void token::transfers(const name &from,
                         const name &to,
                         const std::vector<asset> &quantities,
                         const string &memo)
   {
      for (unsigned int a = 0; a < sizeof(quantities); a = a + 1)
      {
         check(from != to, "cannot transfer to self");
         require_auth(from);
         check(is_account(to), "to account does not exist");
         auto sym = quantities[a].symbol.code();
         stats statstable(get_self(), sym.raw());
         const auto &st = statstable.get(sym.raw());

         require_recipient(from);
         require_recipient(to);

         check(quantities[a].is_valid(), "invalid quantity");
         check(quantities[a].amount > 0, "must transfer positive quantity");
         check(quantities[a].symbol == st.supply.symbol, "symbol precision mismatch");
         check(memo.size() <= 256, "memo has more than 256 bytes");

         auto payer = has_auth(to) ? to : from;

         sub_balance(from, quantities[a]);
         add_balance(to, quantities[a], payer);
      }
   }

token.hpp

[[eosio::action]] void transfers(const name &from,
                                       const name &to,
                                       const std::vector<asset> &quantities,
                                       const string &memo);

transaction

cleos -u https://testnet.wax.eosdetroit.io push transaction '{
  "delay_sec": 0,
  "max_cpu_usage_ms": 0,
  "actions": [
    {
      "account": "wallet1",
      "name": "transfers",
      "data": {
        "from": "wallet1",
        "to": "wallet2",
        "quantities": ["10.0000 TEST", "10.0000 TESTE"],
        "memo": "test mult transfers"
      },
      "authorization": [
        {
          "actor": "wallet1",
          "permission": "active"
        }
      ]
    }
  ]
}'

i get this error.

Error 3050003: eosio_assert_message assertion failure
Error Details:
assertion failure with message: unable to find key
pending console output: 

Fix:

I changed code of sizeof(quantities) to quantities.size()

for (unsigned int a = 0; a < quantities.size(); a = a + 1)
2
  • Please mark your question as solved if you found a solution to your problem.
    – cmadh
    Dec 24, 2021 at 15:24
  • I would like to combine tokens from a few accounts.bwhat command can i use? Sep 11, 2022 at 2:57

0

Your Answer

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

Browse other questions tagged or ask your own question.