Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions doc/src/build/cli-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,25 +507,24 @@ id: 0x471c8e241d0473c34753461529b70f9c4ed3151b[1]

## Publish packages

In order for user-written code to be available in Sui, it must be
*published* to Sui's [distributed ledger](../learn/how-sui-works.md#architecture).
Please see the [Move developer documentation](move/index.md) for a
description on how to [write a simple Move code package](move/write-package.md),
which we can publish using Sui client's `publish` command.
You must publish packages to the Sui [distributed ledger](../learn/how-sui-works.md#architecture) for the code you developed to be available in Sui. To publish packages with the Sui client, use the `publish` command.

The publish command requires that you specify the directory where your package lives using the `--path` parameter. The value is the path to the `my_move_package` as per the [package creation description](move/write-package.md). You must also provide a `gas` object to pay for publishing the package and a `gas-budget` value.

> **Important:** All calls to functions in the `debug` module must be removed from no-test code
> before the new module can be published (test code is marked with the `#[test]` annotation).
Parameters used for the `publish` command example:
* `--path` - Defines the path to the Move package to publish.
* `--gas` - The Coin object used to pay for gas.
* `--gas-budget` - Gas budget for running module initializers.
* `--verify-dependencies` - Optional flag to have the CLI check that a dependency exists on-chain.

The publish command
requires us to specify a directory where the user-defined package lives.
It's the path to the `my_move_package` as per the
[package creation description](move/write-package.md), a gas
object that will be used to pay for publishing the package (we use the
same gas object we used to pay for the function call in the
[Calling Move code](#calling-move-code)) section, and gas budget to put
an upper limit we use 1000 as our gas budget.
Refer to the [Move developer documentation](move/index.md) for a
description on how to [write a simple Move code package](move/write-package.md),
which you can then publish using the Sui client `publish` command.

Let us use the same address for publishing that we used for calling Move code in the previous [section](#calling-move-code) (`0x3cbf06e9997b3864e3baad6bc0f0ef8ec423cd75`) which now has 4 objects left:
> **Important:** You must remove all calls to functions in the `debug` module from no-test code
> before you can publish the new module (test code is marked with the `#[test]` annotation).

Use the same address for publishing that we used for calling Move code in the previous [section](#calling-move-code) (`0x3cbf06e9997b3864e3baad6bc0f0ef8ec423cd75`) which now has four objects left:

```shell
$ sui client objects 0x3cbf06e9997b3864e3baad6bc0f0ef8ec423cd75
Expand All @@ -549,10 +548,22 @@ that the location of the package's sources is in the `PATH_TO_PACKAGE`
environment variable):

```shell
$ sui client publish --path $PATH_TO_PACKAGE/my_move_package --gas-budget 30000
$ sui client publish --path $PATH_TO_PACKAGE/my_move_package --gas 0xc8add7b4073900ffb0a8b4fe7d70a7db454c2e19 --gas-budget 30000 --verify-dependencies
```

The result of running this command should look as follows:
The call uses the optional `--verify-dependencies` flag to verify the bytecode for dependencies found at their respective published addresses matches the bytecode you get when compiling that dependency from source code. If the bytecode for a dependency does not match, your package does not publish and you receive an error message indicating which package and module the mismatch was found:

```shell
Local dependency did not match its on-chain version at <address>::<package>::<module>
```

The `--verify-dependencies` flag can fail the publish for other reasons, as well.
* There are modules missing, either in the local version of the dependency or on-chain.
* There's nothing at the address that the dependency points to (it was deleted or never existed).
* The address supplied for the dependency points to an object instead of a package.
* The CLI fails to connect to the node to fetch the package.

If successful, your response resembles the following:

```shell
----- Certificate ----
Expand All @@ -577,19 +588,18 @@ swords_created: 0
Updated Gas : Coin { id: 0xc8add7b4073900ffb0a8b4fe7d70a7db454c2e19, value: 96929 }
```

Please note that running this command resulted in creating an object representing the published package.
From now on, we can use the package object ID (`0xdbcee02bd4eb326122ced0a8540f15a057d82850`) in the Sui client's call
command just like we used `0x2` for built-in packages in the
[Calling Move code](#calling-move-code) section.
Running this command created an object representing the published package.
From now on, use the package object ID (`0xdbcee02bd4eb326122ced0a8540f15a057d82850`) in the Sui client call
command (similar to `0x2` used for built-in packages in the
[Calling Move code](#calling-move-code) section).

Another object created as a result of package publishing is a
user-defined object (of type `Forge`) crated inside initializer
user-defined object (of type `Forge`) created inside the initializer
function of the (only) module included in the published package - see
the part of Move developer documentation concerning [module
initializers](move/debug-publish.md#module-initializers) for more details on module
initializers.
initializers](move/debug-publish.md#module-initializers) for more details.

Finally, we see that the gas object that was used to pay for
You might notice that the gas object that was used to pay for
publishing was updated as well.

> **Important:** If the publishing attempt results in an error regarding verification failure,
Expand Down
48 changes: 48 additions & 0 deletions doc/src/explore/walkthrough/check-object-details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Check the details of an Object
---

In the previous example, you retrieved the objects your address owns. In this example, you use the `sui_getObject` method to check the <a href="https://docs.sui.io/sui-jsonrpc#sui_getObject">`objectId`</a> for one of those coins and its details. Enter the following commands in your terminal, replacing the given ID with one of the coin object IDs at your address.

```sh
# Set the id as a variable
id="0x91be7b2c011125f748c308872d00c8f200cabe15"
# Create the JSON
data="{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"sui_getObject\", \"params\": [\"$id\"]}"
# Fire the request and save the result in a tmp file
curl -X POST -H 'Content-type: application/json' --data-raw "$data" $rpc > result.json
```

After entering the last command, open the result.json file it created in an editor like Visual Studio Code. Use the editor to format the JSON, if necessary. If successful, your JSON resembles the following:

```JSON
{
"jsonrpc":"2.0",
"result":{
"status":"Exists",
"details":{
"data":{
"dataType":"moveObject",
"type":"0x2::coin::Coin<0x2::sui::SUI>",
"has_public_transfer":true,
"fields":{
"balance":10000000,
"id":{"id":"0x91be7b2c011125f748c308872d00c8f200cabe15"}
}
},
"owner":{"AddressOwner":"0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"},
"previousTransaction":"8Dpc1+03kCviQRrB4hMUDT1z3bF+ZhlHtkG3RXHKuBg=",
"storageRebate":15,
"reference":{"objectId":"0x91be7b2c011125f748c308872d00c8f200cabe15",
"version":1,
"digest":"Bu5RPYiVWDDX4IshFqB8vsUdzBptTkhNK/Hm/b06wEA="}}
},
"id":1
}
```

The same parameters exist for this call as were available with [`sui_getObjectsOwnedByAddress`](/sui-jsonrpc#sui_getObjectsOwnedByAddress) (`digest`, `previousTransaction`, `owner`, `version`, and so on) but are in a slightly different shape with additional data. The `result` object, for example, contains a `details.data.fields.balance` parameter showing a value of `10000000`. This means that this SUI Coin object's value is 10,000,000 SUI. The faucet provided you with five such objects. If you check each one, you discover that their balance is the same.

As mentioned, when you want to acquire another object that is priced in SUI, you need to send a Coin object with the exact balance as its price. You also must provide a Coin object to pay gas for the transaction.

The splitting of Coins to facilitate transactions typically does not require user input or knowledge, so the process occurs quietly. In the next example, you split the coins manually to understand the process.
90 changes: 90 additions & 0 deletions doc/src/explore/walkthrough/check-owned-objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: Check the objects our address owns
---

*In Sui everything is an object.* Sui is object-centric and every object owns a UID. You might not be aware yet, but if you followed the previous steps then your address owns 5 objects that contain a specific amount of SUI tokens tapped from the Discord faucet. When considering SUI tokens, you can think of each Coin object as SUI banknotes. As such, your address actually has 5 banknotes, each with its own, currently equal denomination.

If you want to transfer a SUI amount that is less than the denominated value of your SUI banknote, then you have to make change. To do this, you must split your large banknote into smaller denominations. For example, if you want to send 20,000 SUI to someone but all your banknotes contain 10,000,000 SUI, then you must split one of those banknotes into two smaller SUI banknotes, one with 20,000 SUI and another containing 9,980,000 SUI. You can then complete the transfer with your newly minted 20,000 SUI. In the end, you created two new SUI banknotes and deleted the original one. The actual process of splitting SUI objects typically completes without any direct involvement on your part, but is useful to understand.

As mentioned, your address should now have SUI assigned. To check, you can make an RPC call using the [`sui_getObjectsOwnedByAddress`](/sui-jsonrpc#sui_getObjectsOwnedByAddress). For ease of use on a command line, save the JSON payload to a variable before making the actual call.

```sh
data="{\"jsonrpc\": \"2.0\", \"method\": \"sui_getObjectsOwnedByAddress\", \"id\": 1, \"params\": [\"$address\"]}"
```
Make the call using cURL:

```sh
curl -X POST -H 'Content-type: application/json' --data-raw "$data" $rpc
```

If successful, the JSON response has the following shape:

```JSON
{
"jsonrpc": "2.0",
"result": [
{
"objectId": "0x91be7b2c011125f748c308872d00c8f200cabe15",
"version": 1,
"digest": "Zusbw800Wk4+vpkei8JQD+EJiQEf8PvmdIQokHwX0N0=",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"owner": {
"AddressOwner": "0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"
},
"previousTransaction": "B2015vW4kYmFXLsBw/njGWUOQHdmszg8jsdygrUFTPw="
},
{
"objectId": "0x9f0afe6a6c3d72d281003b6f87ea84703113744c",
"version": 1,
"digest": "m0M5XSe4MLQWsz1mAPFAH8iztx8VHnZPNqYtCb4fc1k=",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"owner": {
"AddressOwner": "0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"
},
"previousTransaction": "3DEKooZaVHWiMrdjMb8e1h2kx2J+M9Yu5uJy2CHmgJ4="
},
{
"objectId": "0xb2a2f77bbddb5c9c84a2abbfdd282d609274f96b",
"version": 1,
"digest": "w3U7ZJsnpcLB+NPiFTGrOz58I/a9TRz0YPGFRPdjm6o=",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"owner": {
"AddressOwner": "0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"
},
"previousTransaction": "E5CGmStqkRq7fB6MPwLx5MBbR8MNtzFEiNVRnfNL3s8="
},
{
"objectId": "0xbb2d9b82ecc54012640d3cef122de4f394f8aa15",
"version": 1,
"digest": "dvRriMle+XIC9WHN0nEj+KD5rPWhLYBeXeFLAeCDSu8=",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"owner": {
"AddressOwner": "0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"
},
"previousTransaction": "bKioOVWJBniAlT1SlVUsspIiDDZABS+nvROSu3/RZmA="
},
{
"objectId": "0xe9c85a7f49c0d0652685690dbd552fe17a83bd2e",
"version": 1,
"digest": "BptpMcUxbtjN0D9CGvtqSwS9odmEfW9pho+aIF/MiA4=",
"type": "0x2::coin::Coin<0x2::sui::SUI>",
"owner": {
"AddressOwner": "0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"
},
"previousTransaction": "lBnZ6OXExGfd0C5EzCLlR2gXAT/aTn0EnOvwF5KJEOU="
}
],
"id": 1
}
```

> **NOTE:** The response you receive in the terminal is not prettified like this example output, so it's a little difficult to parse. From this point forward, the example commands save the output to a JSON file so that you can more readily format the response if you're following along.

The details of the response offers some observations into objects on the Sui network. For instance,
* `objectId` - Each object in the result has a UID assigned to its `objectId` parameter. This ID is unique for each object in the Sui network.
* `type` - Each object also has a `type` parameter set to `0x2::coin::Coin<0x2::sui::SUI`, where the `0x2` address can contain a number of packages that are native to Sui, like the SUI Coin module, the transfer function, the `TxContext` global object, and so on. In the case of this example, each object has a `type` of `0x2::sui::SUI`, which are SUI tokens.
* `owner` - The `owner` object provides the address of the object's current owner.
* `previousTransaction` - Every object has a `previousTransaction` value to verify its placement on-chain.
* `version` - The `version` value reports the number of transactions an object has been through. Because all the coins in this example are freshly minted by faucet, they have experienced a single transaction so far: `"version": 1`.

Your address now has Coins assigned to it and you have retrieved a list of those objects. In the next example, you take a closer look at one of those Coins.
43 changes: 43 additions & 0 deletions doc/src/explore/walkthrough/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: JSON RPC Examples
---

Welcome to this walkthrough of the Sui JSON Remote Procedure Call (RPC) protocol. Using the following series of examples, you interact with the Sui network to create and manipulate objects on the blockchain using the Sui Client CLI.

## Prerequisites

What you need:
* Sui Client CLI (installed when you install Sui). To check if you have Sui installed, type `which sui` in a command-line shell (terminal) window. If the terminal does not echo a path, you need to [install Sui](/devnet/build/install).
* An active address, preferably without any objects. You create an address when you first connect to Devnet with the `sui client` command. If you need a new address, use the `sui client new-address ed25519` command to create one with an `ed25519` key scheme.
* cURL is used in the examples. You can modify these calls to the language of your choice. If you need help installing, refer to the [Install Sui to Build](/build/install) topic.
* The examples use Git to download code from the internet. If you need help installing, refer to the [Install Sui to Build](/build/install) topic.

## Setup

**Note:** When reading about Sui, you often see Sui capitalized as both "Sui" and "SUI". Sui refers to the network, and SUI, all capital letters, refers to the token.

Open a terminal window. If you are following along using cURL, use the same terminal window for all the commands in these examples.

To begin, make sure your address exists and store its value to a variable to limit the amount of typing required in subsequent commands:

```sh
sui client active-address
# 0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12
address="0xfc08bf8efcc3db36218a9a315ff6c7a0bf0d3d12"
```

**Note:** Sample values are provided throughout these examples to demonstrate what they should look like. Make sure to change them to the specific values for your environment.

If the sui command does not return an address, [connect to Sui Devnet](https://docs.sui.io/build/devnet) to get one.

To complete the following calls, you need to add SUI to your address. If using Devnet, join our [discord channel](https://discord.gg/sui) if you haven't already. After you are verified, type `!faucet <address>` in the the [devnet-faucet](https://discord.com/channels/916379725201563759/971488439931392130) channel, where `<address>` is the value you retrieve from the `sui client active-address` command.

If using a local installation, then add SUI to your address.

To complete setup, bind the devnet rpc server URL to a variable:

```sh
rpc="https://fullnode.devnet.sui.io:443"
```

Now, you are ready to make your first call and see the SUI you own.
Loading