In the below code, I am passing parameters to actions struct which takes account_name, action_name, permission vector and arguments. But while sending the account_name using N
it is taking the exact value of account i.e. account_name
not what is the value of this variable. I tried using hard coding the account_name and it worked.
So, the question is how to send the account_name as variable while setting the actions in a transaction.
void send(account_name account, std::string message) {
eosio::transaction t{};
t.actions.emplace_back(
eosio::permission_level(account, N(active)),
N(account), // right now it is sending account as it is, not the value that it contains i.e. eosio
N(action), // works fine for this
std::make_tuple(message)
);
}
1 Answer
So, the question is how to send the account_name as variable while setting the actions in a transaction.
N(account)
is a preprocessor macro defined in the eosio
codebase to convert the literal string "account"
into an uint64_t
based on its base32 representation. So, in your case, you only have to use account
(which is already uint64_t
) instead of N(account)
.
In the comments, you asked:
In above code, we have to pass the account_name at three different places. 1-in permission_level vector, 2-the second argument and 3-in t.send(). Can you explain me what permissions are these and which account_name i should use and when
As far as I know, there's not much documentation on this, but my understanding is as follows (someone please correct me if I'm wrong):
- The
account
inpermission_level
is the account whose permissions are needed to send the action, so you would use the account that would give permission when calling the action - The second argument is the account to which the action is sent, so you just use the receiver
account_name
- The third
account
is the payer for the transaction for CPU/NET, and this is also contextually chosen based on the service, but typically the same as the account in the first argument (or_self
if the contract pays themselves)
account
instead ofN(account)