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.

2 Answers 2


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 agree to our terms of service and acknowledge you have read our privacy policy.

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