Skip to content

Commit c81350f

Browse files
committed
feat: add enumeration standard to multi token standard
1 parent 174b92f commit c81350f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Multi Token Enumeration
2+
3+
Version `1.0.0`
4+
5+
## Summary
6+
7+
Standard interfaces for counting & fetching tokens, for an entire Multi Token contract or for a given owner.
8+
9+
## Motivation
10+
11+
Apps such as marketplaces and wallets need a way to show all tokens owned by a given account and to show statistics about all tokens for a given contract. This extension provides a standard way to do so.
12+
13+
While some Multi Token contracts may forego this extension to save [storage] costs, this requires apps to have custom off-chain indexing layers. This makes it harder for apps to integrate with such Multi Token contracts. Apps which integrate only with Multi Token Standards that use the Enumeration extension do not even need a server-side component at all, since they can retrieve all information they need directly from the blockchain.
14+
15+
Prior art:
16+
17+
- [ERC-721]'s enumeration extension
18+
- [NEP-181]'s enumeration extension
19+
20+
## Interface
21+
22+
The contract must implement the following view methods:
23+
24+
```ts
25+
26+
27+
28+
// Get a list of all tokens
29+
//
30+
// Arguments:
31+
// * `from_index`: a string representing an unsigned 128-bit integer,
32+
// representing the starting index of tokens to return
33+
// * `limit`: the maximum number of tokens to return
34+
//
35+
// Returns an array of Token objects, as described above, and an empty array if there are no tokens
36+
function mt_tokens(
37+
from_index: string|null, // default: "0"
38+
limit: number|null, // default: unlimited (could fail due to gas limit)
39+
): Token[] {}
40+
41+
// Get list of all tokens owned by a given account
42+
//
43+
// Arguments:
44+
// * `account_id`: a valid NEAR account
45+
// * `from_index`: a string representing an unsigned 128-bit integer,
46+
// representing the starting index of tokens to return
47+
// * `limit`: the maximum number of tokens to return
48+
//
49+
// Returns a paginated list of all tokens owned by this account, and an empty array if there are no tokens
50+
function mt_tokens_for_owner(
51+
account_id: string,
52+
from_index: string|null, // default: 0
53+
limit: number|null, // default: unlimited (could fail due to gas limit)
54+
): Token[] {}
55+
```
56+
57+
The contract must implement the following view methods if using metadata extension:
58+
59+
```ts
60+
// Get list of all base metadata for the contract
61+
//
62+
// Arguments:
63+
// * `from_index`: a string representing an unsigned 128-bit integer,
64+
// representing the starting index of tokens to return
65+
// * `limit`: the maximum number of tokens to return
66+
//
67+
// Returns an array of BaseTokenMetadata objects, as described above, and an empty array if there are no tokens
68+
function mt_base_token_metadata(
69+
from_index: string | null,
70+
limit: number | null
71+
): BaseTokenMetadata[]
72+
```
73+
74+
75+
## Notes
76+
77+
At the time of this writing, the specialized collections in the `near-sdk` Rust crate are iterable, but not all of them have implemented an `iter_from` solution. There may be efficiency gains for large collections and contract developers are encouraged to test their data structures with a large amount of entries.
78+
79+
[ERC-721]: https://eips.ethereum.org/EIPS/eip-721
80+
[storage]: https://docs.near.org/docs/concepts/storage-staking

0 commit comments

Comments
 (0)