diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml new file mode 100644 index 0000000..4319eb4 --- /dev/null +++ b/.github/workflows/build-docs.yml @@ -0,0 +1,80 @@ +name: Build documentation + +on: + push: + branches: ["main"] + workflow_dispatch: + +permissions: + id-token: write + pages: write + +env: + INSTANCE: 'docs/in' + ARTIFACT: 'webHelpIN2-all.zip' + DOCKER_VERSION: '243.21565' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build docs using Writerside Docker builder + uses: JetBrains/writerside-github-action@v4 + with: + instance: ${{ env.INSTANCE }} + artifact: ${{ env.ARTIFACT }} + docker-version: ${{ env.DOCKER_VERSION }} + + - name: Save artifact with build results + uses: actions/upload-artifact@v4 + with: + name: docs + path: | + artifacts/${{ env.ARTIFACT }} + artifacts/report.json + retention-days: 7 + test: + needs: build + runs-on: ubuntu-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: docs + path: artifacts + + - name: Test documentation + uses: JetBrains/writerside-checker-action@v1 + with: + instance: ${{ env.INSTANCE }} + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: [build, test] + runs-on: ubuntu-latest + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: docs + + - name: Unzip artifact + run: unzip -O UTF-8 -qq '${{ env.ARTIFACT }}' -d dir + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Package and upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: dir + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..409cb4c --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Sui Cookbook + diff --git a/docs/c.list b/docs/c.list new file mode 100644 index 0000000..c4c77a2 --- /dev/null +++ b/docs/c.list @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/docs/cfg/buildprofiles.xml b/docs/cfg/buildprofiles.xml new file mode 100644 index 0000000..25e65be --- /dev/null +++ b/docs/cfg/buildprofiles.xml @@ -0,0 +1,31 @@ + + + + + #7F52FF + contrast + sui-cookbook.svg + sui-cookbook.svg + false + true + https://github.com/mcxross/sui-cookbook + gtm.js + google_analytics_noscript.html + Launch PTB Studio + https://ptb.studio + true + + + + false + + + + diff --git a/docs/cfg/glossary.xml b/docs/cfg/glossary.xml new file mode 100644 index 0000000..50221cf --- /dev/null +++ b/docs/cfg/glossary.xml @@ -0,0 +1,16 @@ + + + + The network that processes production transaction blocks. When you trade SUI or NFTs that are + ultimately based on fiat currency, you are doing so on the Mainnet network of Sui + + Staging network to provide quality assurance that any planned changes to Sui do not adversely + impact performance. Developers can use this network to test their code before placing it in production + + A more unstable network that is used to develop new features. Developers can leverage this + network to code against the latest planned features of Sui + + You can run a Sui network on your local computer. Developing on a local network provides an + optimized workflow in an environment you control + + \ No newline at end of file diff --git a/docs/cfg/google_analytics_noscript.html b/docs/cfg/google_analytics_noscript.html new file mode 100644 index 0000000..a29b66f --- /dev/null +++ b/docs/cfg/google_analytics_noscript.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/docs/cfg/gtm.js b/docs/cfg/gtm.js new file mode 100644 index 0000000..0662557 --- /dev/null +++ b/docs/cfg/gtm.js @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/docs/code-snippets/account.kt b/docs/code-snippets/account.kt new file mode 100644 index 0000000..424bc96 --- /dev/null +++ b/docs/code-snippets/account.kt @@ -0,0 +1,4 @@ +val account = Account.create() + +val account = Account.import("suipri...8cpv0g") +val account = Account.import("abandon salad ...") \ No newline at end of file diff --git a/docs/code-snippets/install.kt b/docs/code-snippets/install.kt new file mode 100644 index 0000000..04f4e03 --- /dev/null +++ b/docs/code-snippets/install.kt @@ -0,0 +1 @@ +implementation("xyz.mcxross.ksui:ksui:<$ksui_version>") \ No newline at end of file diff --git a/docs/code-snippets/sui.kt b/docs/code-snippets/sui.kt new file mode 100644 index 0000000..0bd4603 --- /dev/null +++ b/docs/code-snippets/sui.kt @@ -0,0 +1 @@ +val sui = Sui() \ No newline at end of file diff --git a/docs/code-snippets/zkLogin-android.kt b/docs/code-snippets/zkLogin-android.kt new file mode 100644 index 0000000..3f3c254 --- /dev/null +++ b/docs/code-snippets/zkLogin-android.kt @@ -0,0 +1,27 @@ +private val zkLoginSuccess = mutableStateOf(false) +private var activityResult: ActivityResult? = null +private var zkLoginResponse: ZKLoginResponse? = null + +private val zkLoginResultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + activityResult = result + zkLoginResponse = + result.data?.getStringExtra("zkLoginResponse")?.let { jsonToZKLoginResponse(it) } + zkLoginSuccess.value = true + } else { + Toast.makeText(this, "Login failed", Toast.LENGTH_SHORT).show() + } +} + + + val googleZKIntent = + context zkLogin + ZKLoginRequest( + OpenIDServiceConfiguration( + Google(), + System.getenv("GOOGLE_CLIENT_ID")!!, // Replace with your Google Client ID + System.getenv("GOOGLE_REDIRECT_URI")!!, // Replace with your Google Redirect URI, + ) + ) +launcher.launch(googleZKIntent) \ No newline at end of file diff --git a/docs/images/ptb-studio.png b/docs/images/ptb-studio.png new file mode 100644 index 0000000..71113c4 Binary files /dev/null and b/docs/images/ptb-studio.png differ diff --git a/docs/images/sui-cookbook.svg b/docs/images/sui-cookbook.svg new file mode 100644 index 0000000..299d7f9 --- /dev/null +++ b/docs/images/sui-cookbook.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/docs/in.tree b/docs/in.tree new file mode 100644 index 0000000..befc33a --- /dev/null +++ b/docs/in.tree @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/labels.list b/docs/labels.list new file mode 100644 index 0000000..4c8b6e3 --- /dev/null +++ b/docs/labels.list @@ -0,0 +1,18 @@ + + + + + This is an example label + + + + Go to McXross + + + Work in progress + Beta + + This is an experimental feature + New in version 2023.3 + \ No newline at end of file diff --git a/docs/redirection-rules.xml b/docs/redirection-rules.xml new file mode 100644 index 0000000..e0b5f71 --- /dev/null +++ b/docs/redirection-rules.xml @@ -0,0 +1,12 @@ + + + + + Created after removal of "Development" from SuiCookbook + Help IDs that are no longer available in build after removal: + + Development + + development.html + + \ No newline at end of file diff --git a/docs/topics/Reference.md b/docs/topics/Reference.md new file mode 100644 index 0000000..efd006e --- /dev/null +++ b/docs/topics/Reference.md @@ -0,0 +1,11 @@ +# Reference + +API References for the various SDKs used across the topics. + +[Kotlin Sui SDK API](https://mcxross.github.io/ksui) + +[Kotlin DeepBook SDK API](https://mcxross.github.io/ksui) + +[Kotlin zkLogin SDK](https://zeroauth.dev/) + +[Kotlin BCS SDK API](https://github.com/mcxross/kotlinx-serialization-bcs) diff --git a/docs/topics/Transactions.md b/docs/topics/Transactions.md new file mode 100644 index 0000000..acf41cc --- /dev/null +++ b/docs/topics/Transactions.md @@ -0,0 +1,12 @@ +# Transactions + +Transactions allow us to alter the state of a Blockchain. In Sui, +these transactions are made up of a chain of commands termed +Programmable Transaction Blocks. + +The execution of these commands is an all-or-nothing operation, in that, either all +commands execute successfully or the entire transaction fails. Construction of +these PTBs is either by SDKs or Transaction Builders. + +In this chapter, we'll cover how to construct PTBs with both an SDK and a Transaction +Builder. \ No newline at end of file diff --git a/docs/topics/accounts.md b/docs/topics/accounts.md new file mode 100644 index 0000000..39f651b --- /dev/null +++ b/docs/topics/accounts.md @@ -0,0 +1,92 @@ +# Accounts + +## Creating new Accounts + +To create a new Sui Account, simply invoke the static `create` method on the `Account` class. + +```kotlin +``` + +{ src="account.kt" include-lines="1" } + +## Importing an existing Account + +In case you already have existing account credentials like a Bech32 encoded private key or +passphrase that you'd like to import and use. + +For a private key: + +```kotlin +``` + +{ src="account.kt" include-lines="3" } + +For a passphrase: + +```kotlin +``` + +{ src="account.kt" include-lines="4" } + +## Get Account Balance + +Once you've an `account`, you can either retrieve the balance for a specific coin type or for +all coin types. + +For a specific coin type: + +```kotlin +val suiBalance = [[[sui|getting-started.topic#sui-client]]].getBalance(account.address) +``` + +This defaults to the `0x2::sui::SUI` coin type, or you can pass a particular coin type argument to the `type` parameter +as shown below: + +```kotlin +val particularTypeBalance = [[[sui|getting-started.topic#sui-client]]].getBalance(account.address, PARTICULAR_TYPE) +``` + +You can also simply retrieve all coin type balances as follows: + +```kotlin +val allBalances = [[[sui|getting-started.topic#sui-client]]].getAllBalances(account.address) +``` + +## Get Account Objects + +You can also retrieve objects owned by a given account address: + +```kotlin +val ownedObjects = [[[sui|getting-started.topic#sui-client]]].getOwnedObjects(account.address) +``` + +## Get Account Coins + +Account Coins retrieval also follows the same pattern + +```kotlin +val coins = [[[sui|getting-started.topic#sui-client]]].getCoins(account.address) +``` + +## Get Account Stakes + +You can fetch stakes for an account as follows: + +```kotlin +val stakes = [[[sui|getting-started.topic#sui-client]]].getStakes(account.address) +``` + +## Resolve Account Name Service Names + +```Kotlin +val names = [[[sui|getting-started.topic#sui-client]]].resolveNameServiceNames(account.address) +``` + +## Request Test Tokens + +If your `Sui()` client is configured for testnet, you can request test tokens from a faucet +as follows: + +```kotlin +val response = [[[sui|getting-started.topic#sui-client]]].requestTestTokens(account.address) +``` \ No newline at end of file diff --git a/docs/topics/bcs.topic b/docs/topics/bcs.topic new file mode 100644 index 0000000..15953d4 --- /dev/null +++ b/docs/topics/bcs.topic @@ -0,0 +1,67 @@ + + + + + +

+ Binary Canonical Serialization is an efficient binary format for structured data, + ensuring consistent serialization across platforms. This format is used extensively by Sui, so it is worth + touching. +

+ + +

It is available for various platforms, and we can install it by adding a dependency for a platform + as follows: +

+ + + + implementation("xyz.mcxross.bcs:<bcs-[platform]>:<$bcs_version>") + + + + + implementation("xyz.mcxross.bcs:bcs:<$bcs_version>") + + + + + implementation("xyz.mcxross.bcs:bcs-android:<$bcs_version>") + + + + + implementation("xyz.mcxross.bcs:bcs-jvm:<$bcs_version>") + + + +
+ + + +

In order to serializer a user defined type, first make a class serializable by annotating it with @Serializable +

+ +@Serializable +data class Data( + val long: Long, + val double: Double, + val string: String, + val boolean: Boolean +) + +

You can now serialize an instance of this class by calling Bcs.encodeToByteArray()

+ +val bcs = Bcs.encodeToByteArray(Data(1_000_000, 3.14159265359, "çå∞≠¢õß∂ƒ∫", false)) +
+ + +

To deserialize an object from BCS, use the decodeFromByteArray() static methode:

+ + val obj = Bcs.decodeFromByteArray<Data>(bcs) + +
+
\ No newline at end of file diff --git a/docs/topics/deepbook.md b/docs/topics/deepbook.md new file mode 100644 index 0000000..27a5b8b --- /dev/null +++ b/docs/topics/deepbook.md @@ -0,0 +1,3 @@ +# DeepBook + +TBA \ No newline at end of file diff --git a/docs/topics/ext-technology.md b/docs/topics/ext-technology.md new file mode 100644 index 0000000..e027f96 --- /dev/null +++ b/docs/topics/ext-technology.md @@ -0,0 +1,5 @@ +# Extended Technology + +This topic covers every other Sui technology that is not part of the core technologies. +It is important to mention that the term "core" is used loosely. + diff --git a/docs/topics/getting-started.topic b/docs/topics/getting-started.topic new file mode 100644 index 0000000..825659d --- /dev/null +++ b/docs/topics/getting-started.topic @@ -0,0 +1,112 @@ + + + + +

+ In this chapter, we'll see how to install Sui binaries and how to add Sui client libraries + as dependencies. Let's start with installing Sui binaries. +

+ +

+ Installing Sui for development is very easy with package managers. In your OS' terminal or shell, run the + appropriate command as shown below: +

+ + + + brew install sui + + + + + brew install sui + + + + + choco install sui + + + +
+ +

+ In order to interact with Sui, we need a client. If you've run either of the above + commands, you have a binary client installed that you can confirm by running sui --version + in you terminal or shell. If successful, this should display the version of Sui installed. +

+ +

+ To add a library client to your project, follow the instructions below: +

+ + +

+ The client libraries are available for various platforms. Ranging from specific platform + libraries to multiplatform libraries. Follow the instructions below: +

+ + + + implementation("xyz.mcxross.ksui:<ksui-[platform]>:<$ksui_version>") + + + +

+ If you have a Kotlin Multiplaform project, add the following dependency to your projects' common sourceSet: +

+
+ + implementation("xyz.mcxross.ksui:ksui:<$ksui_version>") + +
+ +

+ For a purely Android project, add the following as a dependency: +

+
+ + implementation("xyz.mcxross.ksui:ksui-android:<$ksui_version>") + +
+ +

+ For a JVM projects, add the following as a dependency: +

+ + implementation("xyz.mcxross.ksui:ksui-jvm:<$ksui_version>") + +
+
+
+ + +

Create a Sui instance. This is the entry point for the client

+ + val sui = Sui() + + The default connection network is devnet. To change this: + + val config = SuiConfig(settings = SuiSettings(network = Network.MAINNET)) + val sui = Sui(config) + + + The Sui Client is heavily configurable. You can set things like connectAttempts, + retryOnServerErrors, proxy, and much more. + + Simply pass a ClientConfig object to the settings: + + + val settings = SuiSettings(clientConfig = ClientConfig(maxRetries = 5)) + val sui = Sui(SuiConfig(settings)) + + +

+ Our client is now ready for use. We can now call the various available methods on this sui object. +

+
+ +
\ No newline at end of file diff --git a/docs/topics/misc.md b/docs/topics/misc.md new file mode 100644 index 0000000..4500831 --- /dev/null +++ b/docs/topics/misc.md @@ -0,0 +1,3 @@ +# Misc + +Everything else pertaining to Sui that's good to know \ No newline at end of file diff --git a/docs/topics/programmable-transaction-blocks.md b/docs/topics/programmable-transaction-blocks.md new file mode 100644 index 0000000..e8346d0 --- /dev/null +++ b/docs/topics/programmable-transaction-blocks.md @@ -0,0 +1,72 @@ +# Programmable Transaction Blocks + +The Kotlin SDK does a great job by abstracting PTB construction using a simple +expressive Domain Specific Language as we'll explore below. + +The `programmableTx {}` DSL block is the top most block that creates a typed scope for PTB construction. Within it, we can +call all available commands, pass their results to the next command and so forth. + +For example, the Sui `moveCall` command expects a mandatory `target` argument, optional`arguments`, and +`typedArguments` argument. The natural mapping for these is the `moveCall` within `programmableTx` DSL, +where each property (target, arguments, and typedArgument) is used directly with matching names. + +Let's see how to call `hello_world` **Move** **function** in the `hello_wolrd` **module** of +`0x883393ee444fb828aa0e977670cf233b0078b41d144e6208719557cb3888244d` **package**. The function +has the following signature: + +```Rust +[[[public entry fun hello_world(arg0: u64)|https://testnet.suivision.xyz/package/0x883393ee444fb828aa0e977670cf233b0078b41d144e6208719557cb3888244d?tab=Code]]] +``` + +Things to note, the function expects a `u64` as an argument. Has no type parameters. The module name and package. Click on it for details. + +Given the above properties, we can call it as follows: + +```Kotlin +val ptb = programmableTx { + command { + moveCall { + target = "0x883393ee444fb828aa0e977670cf233b0078b41d144e6208719557cb3888244d::hello_wolrd::hello_world" + typeArguments = emptyList() + arguments = inputs(0UL) + } + } +} +``` + +You can also pass results from one command to the next by storing them in a variable, as shown below: + +```Kotlin +val ptb = programmableTx { + command { + val splitCoins = splitCoins { + coin = Argument.GasCoin + into = inputs(1_000_000UL) + } + + transferObjects { + objects = inputs(splitCoins) + to = input(alice.address) + } + } +} +``` + +## Transaction Block Dry Run + +Simulate a transaction before execution: + +```Kotlin +val result = [[[sui|getting-started.topic#sui-client]]].dryRunTransactionBlock(ptb) +``` + +## Sign And Execute Transaction Block + +Once you've constructed, you can sign and execute it: + +```Kotlin +val result = [[[sui|getting-started.topic#sui-client]]].signAndExecuteTransactionBlock(alice, ptb) +``` + +In the next section of Transactions, we're going to see how to visually compose PTBs using +**[PTB Studio](https://ptb.studio)**. \ No newline at end of file diff --git a/docs/topics/ptb-studio.md b/docs/topics/ptb-studio.md new file mode 100644 index 0000000..22ccd65 --- /dev/null +++ b/docs/topics/ptb-studio.md @@ -0,0 +1,10 @@ +# PTB Studio + +[PTB Studio](https://ptb.studio) is your one-stop shop for everything Sui Transactions. +With it, you can construct, visualize and execute transactions. + +Watch the video below to learn more: + +