From 4478400537f807bfaba331f133369250f44522ec Mon Sep 17 00:00:00 2001 From: Michael Hayes Date: Tue, 25 Jul 2023 16:31:44 -0700 Subject: [PATCH] fix formatting --- sdk/docs/pages/typescript-sdk/connect.mdx | 21 +++--- sdk/docs/pages/typescript-sdk/hello-sui.mdx | 75 +++++++++++++-------- sdk/docs/pages/typescript-sdk/install.mdx | 18 +++-- 3 files changed, 75 insertions(+), 39 deletions(-) diff --git a/sdk/docs/pages/typescript-sdk/connect.mdx b/sdk/docs/pages/typescript-sdk/connect.mdx index 8f3aa5ae6ea83..5aa0358f29fcf 100644 --- a/sdk/docs/pages/typescript-sdk/connect.mdx +++ b/sdk/docs/pages/typescript-sdk/connect.mdx @@ -1,21 +1,24 @@ # Connecting to Sui Network -The Sui TypeScript SDK provides a SuiClient class that you can use to connect to a network's JSON-RPC server. Use the `SuiClient` for all JSON-RPC operations. +The Sui TypeScript SDK provides a SuiClient class that you can use to connect to a network's +JSON-RPC server. Use the `SuiClient` for all JSON-RPC operations. ## Network locations The following table lists the locations for the Sui network and the default local network settings. -| Network | Full node | faucet | -| --- | --- | --- | -| local | `http://127.0.0.1:9000` | `http://127.0.0.1:9123/gas` | -| Devnet | `https://fullnode.devnet.sui.io:443` | `https://faucet.devnet.sui.io/gas` | +| Network | Full node | faucet | +| ------- | ------------------------------------- | ----------------------------------- | +| local | `http://127.0.0.1:9000` | `http://127.0.0.1:9123/gas` | +| Devnet | `https://fullnode.devnet.sui.io:443` | `https://faucet.devnet.sui.io/gas` | | Testnet | `https://fullnode.testnet.sui.io:443` | `https://faucet.testnet.sui.io/gas` | -| Mainnet | `https://fullnode.mainnet.sui.io:443` | `null` | +| Mainnet | `https://fullnode.mainnet.sui.io:443` | `null` | ## Using SuiClient to connect to a Sui network -To establish a connection to a network, import `SuiClient` from `@mysten/sui.js/client` and pass the relevant URL to the `url` parameter. The following example establishes a connection to Testnet and requests SUI from that network's faucet. +To establish a connection to a network, import `SuiClient` from `@mysten/sui.js/client` and pass the +relevant URL to the `url` parameter. The following example establishes a connection to Testnet and +requests SUI from that network's faucet. ```typescript import { SuiClient } from '@mysten/sui.js/client'; @@ -32,4 +35,6 @@ await suiClient.getCoins({ }); ``` -For local development, you can run `cargo run --bin sui-test-validator` to spin up a local network with a local validator, a Full node, and a faucet server. Refer to [the Local Network guide](https://docs.sui.io/build/sui-local-network) for more information. \ No newline at end of file +For local development, you can run `cargo run --bin sui-test-validator` to spin up a local network +with a local validator, a Full node, and a faucet server. Refer to +[the Local Network guide](https://docs.sui.io/build/sui-local-network) for more information. diff --git a/sdk/docs/pages/typescript-sdk/hello-sui.mdx b/sdk/docs/pages/typescript-sdk/hello-sui.mdx index ea3a384675a72..255b7c7318c0f 100644 --- a/sdk/docs/pages/typescript-sdk/hello-sui.mdx +++ b/sdk/docs/pages/typescript-sdk/hello-sui.mdx @@ -2,30 +2,41 @@ import { Callout } from 'nextra/components'; -This basic example introduces you to the Sui TypeScript SDK. The Node.js example mints SUI on a Sui network and then queries the address to get a sum for the owned SUI. You don't need to use an IDE to complete the example, but one like Microsoft Visual Studio Code helps centralize more advanced projects. +This basic example introduces you to the Sui TypeScript SDK. The Node.js example mints SUI on a Sui +network and then queries the address to get a sum for the owned SUI. You don't need to use an IDE to +complete the example, but one like Microsoft Visual Studio Code helps centralize more advanced +projects. ## Before you begin -You need an address on a Sui development network (Devnet, Testnet, local). If you don't already have an address, use the [Sui Client CLI](https://docs.sui.io/build/cli-client) or the [Sui Wallet browser extension](https://docs.mystenlabs.com/wallet) to create one. +You need an address on a Sui development network (Devnet, Testnet, local). If you don't already have +an address, use the [Sui Client CLI](https://docs.sui.io/build/cli-client) or the +[Sui Wallet browser extension](https://docs.mystenlabs.com/wallet) to create one. -You also need [Node.js](https://nodejs.org/en/download/current) and a package manager like [pnpm](https://pnpm.io/installation) to follow this example, so install them on your system if you haven't already. +You also need [Node.js](https://nodejs.org/en/download/current) and a package manager like +[pnpm](https://pnpm.io/installation) to follow this example, so install them on your system if you +haven't already. ## Start a project -Using a Terminal or Console, create a folder on your system (`hello-sui` in this example) and make it the working directory. +Using a Terminal or Console, create a folder on your system (`hello-sui` in this example) and make +it the working directory. ```sh mkdir hello-sui cd hello-sui ``` -When you use a package manager to install the necessary packages, it downloads the modules to your `node_modules` folder and adds the references to your `package.json` file, creating the file if it doesn't already exist. For this example, you need only the Sui TypeScript SDK: +When you use a package manager to install the necessary packages, it downloads the modules to your +`node_modules` folder and adds the references to your `package.json` file, creating the file if it +doesn't already exist. For this example, you need only the Sui TypeScript SDK: ```sh npm2yarn npm i -D @mysten/sui.js ``` -Your `package.json` file now has a *dependencies* section with `@mysten/sui.js` listed with the package version number. +Your `package.json` file now has a _dependencies_ section with `@mysten/sui.js` listed with the +package version number. ```json "dependencies": { @@ -35,9 +46,10 @@ Your `package.json` file now has a *dependencies* section with `@mysten/sui.js` ## Get some SUI for your account -Instead of a 'Hello World' output to your console, this example introduces some SUI to your wallet address. You must be on Devnet, Testnet, or a local network to use a faucet for minting SUI. +Instead of a 'Hello World' output to your console, this example introduces some SUI to your wallet +address. You must be on Devnet, Testnet, or a local network to use a faucet for minting SUI. -Create a new `index.js` file in the root of your project with the following code. +Create a new `index.js` file in the root of your project with the following code. ```js import { requestSuiFromFaucetV0, getFaucetHost } from '@mysten/sui.js/faucet'; @@ -48,34 +60,38 @@ const SUI_NETWORK = 'https://fullnode.devnet.sui.io:443/'; const MY_ADDRESS = ''; // Create a new SuiClient object pointing to the network you want to use. -const suiClient = new SuiClient({url: SUI_NETWORK}) +const suiClient = new SuiClient({ url: SUI_NETWORK }); // Function to process the JSON that getCoins provides and then return number of SUI. const balance = (coins) => { - let bal = 0; - coins.data.map((coin) => bal += Number(coin.balance)); - return bal/1000000000; -} + let bal = 0; + coins.data.map((coin) => (bal += Number(coin.balance))); + return bal / 1000000000; +}; // Store the JSON representation for the SUI the address owns before using faucet. const coinsBefore = await suiClient.getCoins({ - owner: MY_ADDRESS -}) - + owner: MY_ADDRESS, +}); + const statusId = await requestSuiFromFaucetV0({ - // Use getFaucetHost to make sure you're using correct faucet address. - // You can also just use the address (see Connecting to Sui Network topic for values). - host: getFaucetHost('testnet'), - recipient: MY_ADDRESS -}) + // Use getFaucetHost to make sure you're using correct faucet address. + // You can also just use the address (see Connecting to Sui Network topic for values). + host: getFaucetHost('testnet'), + recipient: MY_ADDRESS, +}); // Store the JSON representation for the SUI the address owns after using faucet. const coinsAfter = await suiClient.getCoins({ - owner: MY_ADDRESS -}) + owner: MY_ADDRESS, +}); // Output result to console. -console.log(`Balance before faucet: ${balance(coinsBefore)} SUI. Balance after: ${balance(coinsAfter)} SUI. Hello, SUI!`); +console.log( + `Balance before faucet: ${balance(coinsBefore)} SUI. Balance after: ${balance( + coinsAfter, + )} SUI. Hello, SUI!`, +); ``` Save the file, then use Node.js to run it in your Console or Terminal: @@ -84,10 +100,15 @@ Save the file, then use Node.js to run it in your Console or Terminal: node index.js ``` -The code imports the `requestSuiFromFaucetV0` function from the SDK and calls it to mint SUI for the provided address. The code also imports `SuiClient` to create a new client on the Sui network that it uses to query the address and output the amount of SUI the address owns before and after using the faucet. You can check the total SUI for your address using the Sui Wallet or Sui Client CLI. +The code imports the `requestSuiFromFaucetV0` function from the SDK and calls it to mint SUI for the +provided address. The code also imports `SuiClient` to create a new client on the Sui network that +it uses to query the address and output the amount of SUI the address owns before and after using +the faucet. You can check the total SUI for your address using the Sui Wallet or Sui Client CLI. -Faucets on Devnet and Testnet are rate limited. If you run the script too many times, you surpass the limit and must wait to successfully run it again. + Faucets on Devnet and Testnet are rate limited. If you run the script too many times, you surpass + the limit and must wait to successfully run it again. -You can also use the [Sui Client CLI](https://docs.sui.io/build/cli-client) to perform client calls on a Sui network. \ No newline at end of file +You can also use the [Sui Client CLI](https://docs.sui.io/build/cli-client) to perform client calls +on a Sui network. diff --git a/sdk/docs/pages/typescript-sdk/install.mdx b/sdk/docs/pages/typescript-sdk/install.mdx index 29729ef2a99d3..b6226b67af438 100644 --- a/sdk/docs/pages/typescript-sdk/install.mdx +++ b/sdk/docs/pages/typescript-sdk/install.mdx @@ -10,9 +10,14 @@ To use the Sui TypeScript SDK in your project, run the following command in your npm i -D @mysten/sui.js ``` -## Experimental tag for use with a local Sui network +## Experimental tag for use with a local Sui network -Projects developing against one of the on-chain Sui networks (Devnet, Testnet, Mainnet) should use the base SDK published in the NPM registry (previous section) because the code aligns with the relevant JSON-RPC. If your developing against a [local network](https://docs.sui.io/testnet/build/sui-local-network) built from the `main` branch of the Sui monorepo, however, you should use the `experimental`-tagged SDK package as it contains the latest features (or a local build detailed in the section that follows). +Projects developing against one of the on-chain Sui networks (Devnet, Testnet, Mainnet) should use +the base SDK published in the NPM registry (previous section) because the code aligns with the +relevant JSON-RPC. If your developing against a +[local network](https://docs.sui.io/testnet/build/sui-local-network) built from the `main` branch of +the Sui monorepo, however, you should use the `experimental`-tagged SDK package as it contains the +latest features (or a local build detailed in the section that follows). ```sh npm2yarn npm i -D @mysten/sui.js@experimental @@ -20,7 +25,9 @@ npm i -D @mysten/sui.js@experimental ## Install from local build -To build the SDK from the [Sui monorepo](https://github.com/MystenLabs/sui), you must use [pnpm](https://pnpm.io/). With pnpm installed, run the following command from the `sui` root directory: +To build the SDK from the [Sui monorepo](https://github.com/MystenLabs/sui), you must use +[pnpm](https://pnpm.io/). With pnpm installed, run the following command from the `sui` root +directory: ```bash # Install all dependencies @@ -29,7 +36,10 @@ pnpm install pnpm sdk build ``` -With the SDK built, you can import the library from your `sui` project. To do so, use a path to the `sui/sdk/typescript` directory that is relative to your project. For example, if you created a folder `my-sui-project` at the same level as `sui`, use the following to import the locally built Sui Typescript package: +With the SDK built, you can import the library from your `sui` project. To do so, use a path to the +`sui/sdk/typescript` directory that is relative to your project. For example, if you created a +folder `my-sui-project` at the same level as `sui`, use the following to import the locally built +Sui Typescript package: ```bash pnpm add ../sui/sdk/typescript