What is the role of N() in defining tables using multi_index. The primary key function does not return string. Why so? e.g. string primary_key() const {return Some_String_Object}. This throws an error.


The primary key for a multi_index table can not be a string. In general it should be an int.

The N() macro converts the contents within the brackets into a uint64_t.


As per the functionality of multi index table in EOS, primary index must be uint64_t type and unique.

N() refers to the macro defined as:

#define N(p) :: eosio :: string_to_name(#p)

N() is used to generate a compile time uint64_t from base32 encoded string interpretation of p.

For more technical insights, refer: https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/types.hpp

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.