Skip to content

Commit 321dd24

Browse files
committed
chore(ts-sdk-sui): added different examples
Signed-off-by: kaancaglan <[email protected]>
1 parent d9544ce commit 321dd24

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// @ts-ignore
2+
if (typeof BigInt.prototype.toJSON !== "function") {
3+
// @ts-ignore
4+
BigInt.prototype.toJSON = function () {
5+
return this.toString()
6+
}
7+
}
8+
9+
import { Effect, Logger } from "effect"
10+
import { getFullnodeUrl } from "@mysten/sui/client"
11+
12+
import {
13+
PublicClient,
14+
readCoinMetadata,
15+
readCoinBalances,
16+
readTotalCoinBalance,
17+
getAllCoinsUnique,
18+
getCoinName,
19+
getCoinDecimals,
20+
readCoinSymbol,
21+
} from "../src/Sui.js"
22+
23+
const ADDRESS =
24+
process.env.ADDRESS ??
25+
"0x03ff9dd9e093387bdd4432c6a3eb6a1bd5a8f39a530042ac7efe576f18d3232b"
26+
27+
const COIN_TYPE = "0x2::sui::SUI" as any
28+
29+
const program = Effect.gen(function* () {
30+
const { client } = yield* PublicClient
31+
yield* Effect.log("Sui public client initialized", client.network)
32+
33+
const meta = yield* readCoinMetadata(COIN_TYPE)
34+
yield* Effect.log("SUI metadata", meta)
35+
36+
const [name, symbol, decimals] = yield* Effect.all([
37+
getCoinName(COIN_TYPE),
38+
readCoinSymbol(COIN_TYPE),
39+
getCoinDecimals(COIN_TYPE),
40+
])
41+
yield* Effect.log("SUI meta (granular)", { name, symbol, decimals })
42+
43+
yield* Effect.log("Address", ADDRESS)
44+
const coins = yield* readCoinBalances(COIN_TYPE, ADDRESS as any)
45+
yield* Effect.log("SUI coins (objects)", coins)
46+
47+
const total = yield* readTotalCoinBalance(COIN_TYPE, ADDRESS as any)
48+
yield* Effect.log("SUI total balance (mist as BigInt)", total.toString())
49+
50+
51+
const unique = yield* getAllCoinsUnique(ADDRESS as any)
52+
53+
yield* Effect.log("All coins (unique, summed)", unique)
54+
}).pipe(
55+
Effect.provide(PublicClient.Live({ url: getFullnodeUrl("testnet") })),
56+
Effect.provide(Logger.replace(Logger.defaultLogger, Logger.prettyLoggerDefault)),
57+
)
58+
59+
Effect.runPromise(program).catch(console.error)

ts-sdk-sui/examples/sui-create-client-read-and-write.ts renamed to ts-sdk-sui/examples/sui-create-client-write-contract.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
1919

2020
const program = Effect.gen(function* () {
2121
const { client } = yield* PublicClient
22-
yield* Effect.log("Sui public client initialized", client.network )
23-
const meta = yield* readCoinMetadata("0x2::sui::SUI" as any)
24-
yield* Effect.log("SUI metadata", meta)
25-
26-
yield* Effect.log("keypair.getPublicKey().toSuiAddress()", keypair.getPublicKey().toSuiAddress())
27-
const balances = yield* readCoinBalances("0x2::sui::SUI" as any, keypair.getPublicKey().toSuiAddress() as any)
28-
yield* Effect.log("SUI balances", balances)
29-
30-
31-
const wallet = yield* WalletClient
3222
const amountMist = 10_000_000n // 0.01 SUI
3323

3424
const tx = new Transaction()

0 commit comments

Comments
 (0)