- Start with a contract
multi_index_example
which has an actionmod
defined like below in filemulti_index_example.hpp
; the action modifies the integer valuen
stored for row with keyuser
.
class [[eosio::contract]] multi_index_example : public contract {
// ...
[[eosio::action]] void mod( name user, uint32_t n );
// ...
}
- To define an action wrapper for the
mod
action, make use of theeosio::action_wrapper
template, with the first parameter the action name as aeosio::name
and second parameter as the reference to the action method
class [[eosio::contract]] multi_index_example : public contract {
// ...
[[eosio::action]] void mod(name user);
// ...
+ using mod_action = action_wrapper<"mod"_n, &multi_index_example::mod>;
// ...
}
- To use the action wrapper, you have to include the header file where the action wrapper is defined
#include <multi_index_example.hpp>
- Then instantiate the
mod_action
defined above, specifying the contract to send the action to as the first argument. In this case, it is assumed the contract is deployed tomultiindexex
account, and a structure which is defined by two parameters: the self account, obtained byget_self()
call, and theactive
permission (you can modify these two parameters based on your requirements).
#include <multi_index_example.hpp>
+multi_index_example::mod_action modaction("multiindexex"_n, {get_self(), "active"_n});
- And finally call the
send
method of the action wrapper and pass in themod
action's parameters as positional arguments
#include <multi_index_example.hpp>
multi_index_example::mod_action modaction("multiindexex"_n, {get_self(), 1});
+modaction.send("eostutorial"_n, 1);
For a full example see the multi_index
contract implementation.