Tokens

Token name registry

The Solana name service offers a token names registry. The .token TLD used for name resolution is 6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6
The token meta data is stored in the data of the NameRegistry object (see below for deserialisation/serialisation).
Each registered token as the following domains:
  • mint.token: Which contains the TokenData struct data
  • name.token: Which contains the Mint struct data
For example FIDA has the following domains:
  • EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp.token
  • FIDA.token
For Serum
  • SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt.token
  • SRM.token
The NPM package @bonfida/spl-name-service contains the following methods to fetch token information:
  • getTokenInfoFromMint
  • getTokenInfoFromName
The token registry can be explored here: https://naming.bonfida.org/#/token

Serialisation and Deserialisation

Borsh is used for the deserialization and serialization of the data. Below are the Borsh schemas used:
1
// Rust
2
3
#[derive(BorshSerialize, BorshDeserialize)]
4
pub struct TokenData {
5
pub name: String,
6
pub ticker: String,
7
pub mint: [u8; 32],
8
pub decimals: u8,
9
pub website: Option<String>,
10
pub logo_uri: Option<String>,
11
}
12
13
#[derive(BorshSerialize, BorshDeserialize)]
14
pub struct Mint {
15
pub mint: [u8; 32],
16
}
17
18
// Typescript
19
20
export class TokenData {
21
name: string;
22
ticker: string;
23
mint: Uint8Array;
24
decimals: number;
25
website?: string;
26
logoUri?: string;
27
28
constructor(obj: {
29
name: string;
30
ticker: string;
31
mint: Uint8Array;
32
decimals: number;
33
website?: string;
34
logoUri?: string;
35
}) {
36
this.name = obj.name;
37
this.ticker = obj.ticker;
38
this.mint = obj.mint;
39
this.decimals = obj.decimals;
40
this.website = obj?.website;
41
this.logoUri = obj?.logoUri;
42
}
43
44
static schema: Schema = new Map([
45
[
46
TokenData,
47
{
48
kind: "struct",
49
fields: [
50
["name", "string"],
51
["ticker", "string"],
52
["mint", [32]],
53
["decimals", "u8"],
54
["website", { kind: "option", type: "string" }],
55
["logoUri", { kind: "option", type: "string" }],
56
],
57
},
58
],
59
]);
60
61
serialize(): Uint8Array {
62
return serialize(TokenData.schema, this);
63
}
64
static deserialize(data: Buffer) {
65
return deserializeUnchecked(TokenData.schema, TokenData, data) as TokenData;
66
}
67
}
68
69
export class Mint {
70
mint: Uint8Array;
71
constructor(obj: { mint: Uint8Array }) {
72
this.mint = obj.mint;
73
}
74
75
static schema: Schema = new Map([
76
[
77
Mint,
78
{
79
kind: "struct",
80
fields: [["mint", [32]]],
81
},
82
],
83
]);
84
85
serialize(): Uint8Array {
86
return serialize(Mint.schema, this);
87
}
88
static deserialize(data: Buffer) {
89
return deserializeUnchecked(Mint.schema, Mint, data) as Mint;
90
}
91
}
Copied!
Example
1
TokenData {
2
name: 'Bonfida',
3
ticker: 'FIDA',
4
mint: Uint8Array(32) [
5
202, 77, 57, 150, 76, 156, 181, 249,
6
121, 13, 10, 18, 150, 159, 96, 253,
7
151, 36, 147, 98, 132, 234, 74, 18,
8
218, 222, 212, 45, 223, 166, 156, 93
9
],
10
decimals: 6,
11
website: 'https://bonfida.com/',
12
logoUri: 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp/logo.svg'
13
}
Copied!

Resolution example

1
import { Connection, PublicKey } from "@solana/web3.js";
2
import { getTokenInfoFromMint } from "@bonfida/spl-name-service";
3
4
export const resolution = async () => {
5
const connection = new Connection(process.env.URL);
6
const tokenData = await getTokenInfoFromMint(
7
connection,
8
new PublicKey("EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp")
9
);
10
console.log(tokenData);
11
};
12
Copied!

Add your token to the registry

In order to add your token to the registry join our Discord.
Last modified 1mo ago