@@ -209,6 +209,92 @@ const depositInfo = getDepositInfo(tx)
209
209
210
210
You can filter the deposit information sent to your exchange address by ` targetAddress ` and ` tokenId ` .
211
211
212
+ ## Fetching Fungible Token Metadata
213
+
214
+ You can use the API provided by the ` @alephium/web3 SDK ` to fetch fungible token metadata:
215
+
216
+ ``` typescript
217
+ import { NodeProvider } from ' @alephium/web3'
218
+
219
+ const tokenId = ' 1a281053ba8601a658368594da034c2e99a0fb951b86498d05e76aedfe666800'
220
+ const nodeProvider = new NodeProvider (' http://127.0.0.1:12973' )
221
+ const metadata = await nodeProvider .fetchFungibleTokenMetaData (tokenId )
222
+ // {
223
+ // symbol: '4159494e',
224
+ // name: '4159494e',
225
+ // decimals: 18,
226
+ // totalSupply: 1693518090594172274149304n
227
+ // }
228
+ ```
229
+
230
+ The ` symbol ` and ` name ` are hex-encoded UTF-8 strings.
231
+
232
+ You can also use the raw endpoint to fetch fungible token metadata:
233
+
234
+ ``` shell
235
+ curl -X ' POST' \
236
+ ' http://127.0.0.1:12973/contracts/multicall-contract' \
237
+ -H ' accept: application/json' \
238
+ -H ' Content-Type: application/json' \
239
+ -d ' {
240
+ "calls": [
241
+ {
242
+ "group": 0,
243
+ "address": "vT49PY8ksoUL6NcXiZ1t2wAmC7tTPRfFfER8n3UCLvXy",
244
+ "methodIndex": 0
245
+ },
246
+ {
247
+ "group": 0,
248
+ "address": "vT49PY8ksoUL6NcXiZ1t2wAmC7tTPRfFfER8n3UCLvXy",
249
+ "methodIndex": 1
250
+ },
251
+ {
252
+ "group": 0,
253
+ "address": "vT49PY8ksoUL6NcXiZ1t2wAmC7tTPRfFfER8n3UCLvXy",
254
+ "methodIndex": 2
255
+ },
256
+ {
257
+ "group": 0,
258
+ "address": "vT49PY8ksoUL6NcXiZ1t2wAmC7tTPRfFfER8n3UCLvXy",
259
+ "methodIndex": 3
260
+ }
261
+ ]
262
+ }'
263
+ ```
264
+
265
+ All contracts that follow the fungible token standard can use this request to fetch the token metadata. This request calls the contract methods indexed at 0, 1, 2, and 3, which respectively return the token symbol, token name, token decimals, and token total supply.
266
+
267
+ This request uses the token address instead of the token ID. You can refer to the code below to convert the token ID to the token address:
268
+
269
+ ``` typescript
270
+ const tokenAddress = base58 .encode ([0x03 , ... hexToBytes (tokenId )])
271
+ ```
272
+
273
+ The following includes part of the response information for simplicity:
274
+
275
+ ``` json
276
+ {
277
+ "results" : [
278
+ {
279
+ "type" : " CallContractSucceeded" ,
280
+ "returns" : [{ "type" : " ByteVec" , "value" : " 4159494e" }]
281
+ },
282
+ {
283
+ "type" : " CallContractSucceeded" ,
284
+ "returns" : [{ "type" : " ByteVec" , "value" : " 4159494e" }]
285
+ },
286
+ {
287
+ "type" : " CallContractSucceeded" ,
288
+ "returns" : [{ "type" : " U256" , "value" : " 18" }],
289
+ },
290
+ {
291
+ "type" : " CallContractSucceeded" ,
292
+ "returns" : [{ "type" : " U256" , "value" : " 1693518090594172274149304" }]
293
+ }
294
+ ]
295
+ }
296
+ ```
297
+
212
298
## Block APIs
213
299
214
300
### Get block hash with transaction ID
0 commit comments