henriquecbuss / elm-eos / Eos.Name

Name is a very fundamental basic type of EOSIO. It is used to identify accounts, permissions, actions, tables, etc.


type Name

Names are strings of up to 12 characters in length. They can include characters a-z, 1-5, and the dot character (except for the last character).

In order to generate a Name, you can use fromString or decoder.

To display a Name, use the toString function. You can also encode a Name

Converting to and from String

toString : Name -> String

Convert a Name to a regular String. This is useful if you want to display names in your application.

fromString "eosio.token"
    |> Result.map toString
--> Ok "eosio.token"

fromString : String -> Result Error Name

Convert a regular String into a Name. Since there are some restrictions on the possible names, this function can fail with an Error.

fromString "eosio.token"
    |> Result.map toString
--> Ok "eosio.token"

fromString "0123456789"
--> Err (InvalidCharacters ( '0', [ '6', '7', '8', '9' ] ))

fromString "eosio."
--> Err DotInLastPlace

fromString ""
--> Err TooShort

fromString "a.very.long.name"
--> Err TooLong


type Error
    = InvalidCharacters (( Char, List Char ))
    | DotInLastPlace
    | TooShort
    | TooLong

The Error type represents all of the possible errors when converting a Name fromString.

fromString "0123456789"
--> Err (InvalidCharacters ( '0', [ '6', '7', '8', '9' ] ))

fromString "eosio."
--> Err DotInLastPlace

fromString ""
--> Err TooShort

fromString "a.very.long.name"
--> Err TooLong

errorToString : Error -> String

You can use this function to convert an Error into a human-readable String.

Dealing with JSON

encode : Name -> Json.Encode.Value

Encode a Name into JSON. You can use this to send a Name to the blockchain or some server.

decoder : Json.Decode.Decoder Name

Decode a Name from JSON. You can use this to receive a Name from the blockchain or some server. It already does all of the validation necessary to ensure the Name is valid.