Skip to content

Commit a1b6f08

Browse files
committed
chore(ts-sdk-sui): added readCoinMeta function
Signed-off-by: kaancaglan <[email protected]>
1 parent e916e1c commit a1b6f08

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

ts-sdk-sui/src/Sui.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,47 @@ export const readCoinMetadata = (tokenAddress: Address) =>
330330
return metadata
331331
})
332332

333+
/**
334+
* Read Sui coin metadata (name, symbol, decimals) for a given `coinType`.
335+
*
336+
* Example:
337+
* ```ts
338+
* const meta = yield* readCoinMeta("0x2::sui::SUI")
339+
* // -> { name: "Sui", symbol: "SUI", decimals: 9 }
340+
* ```
341+
*
342+
* @param coinType Canonical coin type string (e.g., "0x2::sui::SUI")
343+
* @returns Effect resolving to `{ name, symbol, decimals }`
344+
* @throws ReadCoinError on RPC failure
345+
*
346+
* @category utils
347+
* @since 0.0.0
348+
*/
349+
export const readCoinMeta = (coinType: string) =>
350+
Effect.gen(function* () {
351+
const client = (yield* PublicClient).client
352+
353+
const out = yield* Effect.tryPromise({
354+
try: async () => {
355+
const meta = await client.getCoinMetadata({ coinType })
356+
// meta can be null if the type has no metadata published
357+
if (!meta) {
358+
// normalize to a typed error consistent with your pattern
359+
throw new ReadCoinError({ cause: `No CoinMetadata found for ${coinType}` })
360+
}
361+
const { name, symbol, decimals } = meta
362+
return { name, symbol, decimals }
363+
},
364+
catch: err =>
365+
new ReadCoinError({
366+
cause: extractErrorDetails(err as Error),
367+
}),
368+
})
369+
370+
return out
371+
})
372+
373+
333374
/**
334375
* Read all coin objects for a given `coinType` and owner address.
335376
*
@@ -604,7 +645,6 @@ export const sendInstruction = (params: {
604645
// typeArg?: string
605646
// }>
606647

607-
/** the instruction used purely for encoding operand just like EVM */
608648
instruction: Ucs03.Instruction
609649

610650
}) =>
@@ -631,7 +671,7 @@ export const sendInstruction = (params: {
631671

632672
const tx = new Transaction()
633673
// if (params.gasBudget !== undefined) tx.setGasBudget(BigInt(params.gasBudget as any))
634-
674+
// adress: 0x1234
635675
let sendCtx = tx.moveCall({
636676
target: `${params.packageId}::${module}::begin_send`,
637677
typeArguments: [],

0 commit comments

Comments
 (0)