Category: Coding Mistakes
Using TypeName for display
Informational Impact
Informational Severity
N/A Likelihood
Description
When creating a position NFT, a display object is also created. The code uses property syntax to access coin_type_[a/b]:
struct Position has key, store {
id: UID,
pool: ID,
index: u64,
coin_type_a: TypeName,
coin_type_b: TypeName,
// [...]
let values = vector[
utf8(b"{name}"),
utf8(b"{coin_type_a}"), // <@
utf8(b"{coin_type_b}"), // <@
link,
utf8(b"{url}"),
description,
website,
creator
];
let display = display::new_with_fields<Position>(
publisher, keys, values, ctx
);The coin_type_[a/b] fields are defined as a TypeName rather than as a string. When querying objects with the showDisplay option, TypeName values appear with escape characters:
"coin_type_a": "\n \u001b[1;90mtype\u001b[0m: 0x1::type_name::TypeName\n \u001b[1;90mname\u001b[0m: 61e1...d59e::position::CoinTypeA"Impact
Unnecessary escape characters are included in the display object.
Recommendations
We recommend using the string type for coin_type_a and coin_type_b.