Skip to content

Commit 127a60a

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

19 files changed

+1198
-0
lines changed

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ packages:
99
- 'ts-sdk-evm'
1010
- 'typescript-sdk'
1111
- 'zkgm-dev'
12+
- 'ts-sdk-sui'

ts-sdk-sui/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/**

ts-sdk-sui/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Union.fi Labs, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

ts-sdk-sui/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Union TypeScript SDK for SUI
2+
3+
`@unionlabs/sdk-sui`

ts-sdk-sui/docgen.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "../node_modules/@effect/docgen/schema.json",
3+
"srcLink": "https://github.com/unionlabs/union/tree/main/ts-sdk-sui/src/",
4+
"exclude": ["src/internal/**/*.ts"]
5+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
import { Effect, Logger } from "effect"
9+
import { getFullnodeUrl } from "@mysten/sui/client"
10+
import { PublicClient, WalletClient, writeContract, readCoinMetadata, readCoinBalances } from "../src/Sui.js"
11+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
12+
import { Transaction } from "@mysten/sui/transactions"
13+
14+
const MNEMONIC = process.env.MNEMONIC ?? "fix auto gallery heart practice drip joke nice decline lift attend bread"
15+
const RECIPIENT = process.env.RECIPIENT ?? "0x03ff9dd9e093387bdd4432c6a3eb6a1bd5a8f39a530042ac7efe576f18d3232b"
16+
17+
const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC)
18+
19+
20+
const program = Effect.gen(function* () {
21+
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
32+
const amountMist = 10_000_000n // 0.01 SUI
33+
34+
const tx = new Transaction()
35+
const coin = tx.splitCoins(tx.gas, [tx.pure.u64(amountMist)])
36+
const recipient = tx.pure.address(RECIPIENT)
37+
38+
const res = yield* writeContract(
39+
client,
40+
keypair,
41+
"0x2", // packageId: Sui framework
42+
"transfer", // module: sui::transfer
43+
"public_transfer", // function
44+
["0x2::coin::Coin<0x2::sui::SUI>"], // type arg T
45+
[coin, recipient], // (obj: T, recipient: address)
46+
tx,
47+
)
48+
49+
yield* Effect.log("Transfer submitted", res)
50+
51+
52+
}).pipe(
53+
Effect.provide(PublicClient.Live({ url: getFullnodeUrl("testnet") })),
54+
Effect.provide(
55+
WalletClient.Live({
56+
url: getFullnodeUrl("testnet"),
57+
account: keypair, // signer
58+
chain: "sui-testnet" as any, // placeholder; not used internally
59+
}),
60+
),
61+
62+
Effect.provide(Logger.replace(Logger.defaultLogger, Logger.prettyLoggerDefault)),
63+
)
64+
65+
Effect.runPromise(program).catch(console.error)

ts-sdk-sui/package.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@unionlabs/sdk-sui",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"license": "MIT",
6+
"author": "@unionlabs",
7+
"homepage": "https://docs.union.build/typescript",
8+
"description": "Union TypeScript SDK for Sui",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/unionlabs/union.git",
12+
"directory": "ts-sdk-sui"
13+
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true,
17+
"directory": "dist",
18+
"linkDirectory": false
19+
},
20+
"exports": {
21+
"./package.json": "./package.json",
22+
".": "./src/index.ts",
23+
"./*": "./src/*.ts",
24+
"./examples/*": "./examples/*.ts",
25+
"./internal/*": null
26+
},
27+
"scripts": {
28+
"build": "pnpm build-esm && pnpm build-annotate && pnpm build-cjs && build-utils pack-v3",
29+
"build-annotate": "babel build/esm --plugins annotate-pure-calls --out-dir build/esm --source-maps",
30+
"build-cjs": "babel build/esm --plugins @babel/transform-export-namespace-from --plugins @babel/transform-modules-commonjs --out-dir build/cjs --source-maps",
31+
"build-esm": "tsc -b tsconfig.build.json",
32+
"check": "tsc -b tsconfig.json",
33+
"check:circular": "dpdm -T src",
34+
"check:examples": "tsc -p tsconfig.examples.json",
35+
"codegen": "build-utils prepare-v3",
36+
"test": "vitest run",
37+
"test:watch": "vitest"
38+
},
39+
"peerDependencies": {
40+
"@effect/platform": "^0.84",
41+
"@unionlabs/sdk": "workspace:^",
42+
"@safe-global/safe-apps-sdk": "^9",
43+
"effect": "^3.16",
44+
"viem": "^2"
45+
},
46+
"peerDependenciesMeta": {
47+
"@safe-global/safe-apps-sdk": {
48+
"optional": true
49+
}
50+
},
51+
"devDependencies": {
52+
"@babel/cli": "^7.27.2",
53+
"@babel/core": "^7.27.1",
54+
"@babel/plugin-transform-export-namespace-from": "^7.27.1",
55+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
56+
"@cosmjs/math": "^0.33.1",
57+
"@effect/build-utils": "^0.8.3",
58+
"@effect/platform": "0.84.6",
59+
"@safe-global/safe-apps-sdk": "~9.1.0",
60+
"@types/node": "^22.13.1",
61+
"@unionlabs/sdk": "workspace:^",
62+
"babel-plugin-annotate-pure-calls": "^0.5.0",
63+
"dpdm": "^3.14.0",
64+
"effect": "3.16.3",
65+
"madge": "^8.0.0",
66+
"viem": "^2.33.3",
67+
"vitest": "^3.0.5"
68+
},
69+
"dependencies": {
70+
"@scure/base": "1.2.4",
71+
"crc": "^4.3.2",
72+
"@mysten/sui": "^1.38.0"
73+
}
74+
}

0 commit comments

Comments
 (0)