Problem
I'm trying to emplace a new row in a multi-index table, but it tells me that I don't have the authotity of the row key name to do it.
Code
- Multi-index table definition
struct [[eosio::table]] election {
name election_name;
election_info election_data; // simple struct
uint64_t primary_key() const { return election_name.value; }
};
typedef eosio::multi_index<name("election"), election> elections_table;
- Multi-index table instantiation in upsert action
void evote::upsert(name election_name) {
require_auth(name("evote"));
print("About to create new election...");
// Instantiate multi-index table aka: Get the first row
// (1) Owner of table. (2) Account name this contract is deployed to
// get_self() gets the name of the contract (evote)
elections_table elections(get_self(), get_first_receiver().value);
// Next, query the table for the election.
auto row = elections.find(election_name.value);
// Check if election doesn't exists
if ( row == elections.end() ) {
print("Creating a smoking new election");
// Create election info
election_info info;
elections.emplace(election_name, [&]( auto& row){
row.election_name = election_name;
row.election_data = info;
});
}
// Table exists
else {
print("The election: ", election_name, " exists");
}
}
Environment
I'm running this in a local testnet with a wallet with the keys for two accounts.
- evote: The one setting the contract
- tse: Doesn't do nothing here
This is how I setted the contract
cleos set contract evote ./ -p evote@active
This is the action that I push
cleos push action evote upsert '["eleccion1"]' -p evote@active
Error
It asks for eleccion1 authority, but eleccion1 isn't even an account.
Error 3090004: Missing required authority
Ensure that you have the related authority inside your transaction!;
If you are currently using 'cleos push action' command, try to add the relevant authority using -p option.
Error Details:
missing authority of eleccion1
pending console output: About to create new election...Creating a smoking new election