Skip to content

Commit e7ea531

Browse files
committed
chore(ts-sdk-sui): added new function
Signed-off-by: kaancaglan <[email protected]>
1 parent 127a60a commit e7ea531

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

ts-sdk-sui/src/Sui.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,31 @@ export const readCoinBalances = (contractAddress: string, address: string) =>
344344
return coins
345345
})
346346

347+
export const readTotalCoinBalance = (contractAddress: string, address: string) =>
348+
Effect.gen(function*() {
349+
const client = (yield* PublicClient).client
350+
let params = {
351+
owner: address,
352+
coinType: contractAddress,
353+
}
354+
355+
const coins = yield* Effect.tryPromise({
356+
try: async () => {
357+
const result = await client.getCoins(params)
358+
return result.data
359+
},
360+
catch: err =>
361+
new ReadCoinError({
362+
cause: extractErrorDetails(err as ReadCoinError),
363+
}),
364+
})
365+
// Calculate total balance
366+
const totalBalance = coins.reduce((acc, coin) => acc + BigInt(coin.balance), BigInt(0))
367+
368+
return totalBalance
369+
})
370+
371+
347372
// /**
348373
// * Read the balance of an ERC20 token for a specific address
349374
// *

0 commit comments

Comments
 (0)