1

I have a very simple ACTION in a contract that writes to a table (multi-index) which has two columns: a string name and an auto-generated primary key called id.

This part works fine and I am able to push an action to insert to this table. However, my next step is to test whether or not I can send a context free action from the previous action that created the row so that another action can use the ID generated from the first action and do something with it.

For simplicity's sake, the second action just prints the supplied ID.

I am fairly certain it is the way I am populating the action object but I can't seem to find anything to show me how to do it correctly. Here is the code snippet that populates the action object and calls the send_context_free() method:

[...]

// now send the context free action action act;

 act.account = _self;
 act.name = name("reportid");
 act.data = {static_cast<char>(itr->id)};

 act.send_context_free();

}

and here is the reportid function that send_context_free() is invoking:

ACTION reportid(uint64_t id)
{
        print("context free inline action reports ID: ",id);
}

I'd appreciate any guidance as I am unable to get this to work. When I push the first ACTION, I get

Error 3050003: eosio_assert_message assertion failure

and the detailed log entries are:

2018-10-16T19:13:17.655 thread-0   apply_context.cpp:28          print_debug          ]
[(eossocaltest,additem)->eossocaltest]: CONSOLE OUTPUT BEGIN =====================
The unique ID of the added Item record Hello EOSSOCAL 108 is 5
[(eossocaltest,additem)->eossocaltest]: CONSOLE OUTPUT END   =====================
2018-10-16T19:13:17.655 thread-0   wasm_interface.cpp:929        eosio_assert         ] message: read
2018-10-16T19:13:17.656 thread-0   http_plugin.cpp:580           handle_exception     ] FC Exception encountered while processing chain.push_transaction
2018-10-16T19:13:17.656 thread-0   http_plugin.cpp:581           handle_exception     ] Exception Details: 3050003     eosio_assert_message_exception: eosio_assert_message
assertion failure
assertion failure with message: read
{"s":"read"}
thread-0  wasm_interface.cpp:930 eosio_assert
pending console output:
{"console":""}
thread-0  apply_context.cpp:61 exec_one
2

The EOSIO documentation could frankly be a lot better than it is. With much difficulty, I found out how to invoke the send_context_free() function from within an existing ACTION function of your contract:

 std::vector<permission_level> auths; 

// You can also declare a single permission_level object instead of a vector

 // set authorization size to 0

  auths.clear(); // this is to clear all auths.

// **Below, the funcname is your function's name passed to EOSIO_DISPATCH macro**

  action act(auths,_self,name("funcname"),std::make_tuple(itr->id));

  act.send_context_free();

Also, please keep in mind when and where context free actions can be invoked. Context free actions have access to only limited APIs. You might get a

Exception Details: 3050007 unaccessible_api: Attempt to use unaccessible API

if you are using send_context_free() incorrectly. See https://github.com/EOSIO/eosio.cdt/blob/32c9ae7bfab1104126462d85dafc64a421079925/libraries/eosiolib/action.hpp#L270 for details on this function call.

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.