Skip to content

Commit

Permalink
[SDK] Migrate to major SDK release (#134)
Browse files Browse the repository at this point in the history
* migrates to ts 1.0

* fix lockfile

* Update docs, add changeset

* Also fix dependabot
  • Loading branch information
manolisliolios authored Jun 4, 2024
1 parent 5aafc75 commit f537561
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 144 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-countries-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mysten/suins": minor
---

Updates to use @mysten/sui package. Breaking update.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ updates:
schedule:
interval: 'daily'
allow:
- dependency-name: '@mysten/sui.js'
- dependency-name: '@mysten/sui'
24 changes: 19 additions & 5 deletions documentation/pages/sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ Use the SuiNS SDK to interact with the Sui Name Service. Query SuiNS data in a u

## Installation

```sh npm2yarn
npm i @mysten/suins
```
<Tabs items={['Using @mysten/sui', 'Using @mysten/sui.js']}>
<Tabs.Tab>
To use with the latest version of the Typescript SDK, install using:
```sh npm2yarn
npm i @mysten/suins
```
</Tabs.Tab>
<Tabs.Tab>
To use with the older version (prior to 1.x) of the Typescript SDK (0.54.1), install using:
```sh npm2yarn
npm i @mysten/suins@0.0.3
```
</Tabs.Tab>

</Tabs>



## `SuinsClient`

Expand All @@ -32,7 +46,7 @@ or by passing in the constants (usable for any network).
<Tabs.Tab>
```js
import { SuinsClient } from '@mysten/suins';
import { getFullnodeUrl, SuiClient } from '@mysten/sui.js/client';
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';

// You need a Sui client. You can re-use the Sui client of your project
// (it's not recommended to create a new one).
Expand All @@ -48,7 +62,7 @@ const suinsClient = new SuinsClient({
<Tabs.Tab>
```js
import { SuinsClient } from '@mysten/suins';
import { getFullnodeUrl, SuiClient } from '@mysten/sui.js/client';
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';

// You need a Sui client. You can re-use the Sui client of your project
// (it's not recommended to create a new one).
Expand Down
58 changes: 29 additions & 29 deletions documentation/pages/sdk/transactions.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Building Transactions

`SuinsTransaction` is the client used similar to `TransactionBlock`, and helps in building a transaction.
`SuinsTransaction` is the client used similar to `Transaction`, and helps in building a transaction.
You need to instatiate it once in every programmable transaction block (PTB) that you're building.

## Available functions
Expand All @@ -15,9 +15,9 @@ const register = async (name: string, years: number) => {
// Query the latest price list from the chain.
const priceList = await suinsClient.getPriceList();
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// Build the transaction to register the name.
const nft = suinsTransaction.register({
Expand All @@ -27,7 +27,7 @@ const register = async (name: string, years: number) => {
});

// Transfer the name's NFT
transactionBlock.transferObjects([nft], transactionBlock.pure.address('0xMyAddress'));
transaction.transferObjects([nft], transaction.pure.address('0xMyAddress'));

// ... sign and execute the transaction
}
Expand All @@ -40,9 +40,9 @@ const renew = async (nftId: string, name: string, years: number) => {
// Query the latest pricelist from the chain.
const priceList = await suinsClient.getRenewalPriceList();
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// Build the transaction to renew the name.
suinsTransaction.renew({
Expand All @@ -62,9 +62,9 @@ This works the same for names and subnames.
```js
const setTargetAddress = async (nftId: string, address: string) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// We build the transaction to set the target address.
suinsTransaction.setTargetAddress({
Expand All @@ -84,9 +84,9 @@ This works the same for names and subnames.
```js
const setDefault = async (name: string) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// We build the transaction to set that name as default for the sender.
// Important: This is only possible if the address signing/executing
Expand All @@ -102,9 +102,9 @@ const setDefault = async (name: string) => {
```js
const createSubname = async (subName: string, parentNftId: string, expirationMs: number) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// We build the transaction to create a subname.
const subNameNft = suinsTxb.createSubName({
Expand All @@ -123,7 +123,7 @@ const createSubname = async (subName: string, parentNftId: string, expirationMs:
});

// Transfer the NFT
transactionBlock.transferObjects([subNameNft], transactionBlock.pure.address('0xMyAddress'));
transaction.transferObjects([subNameNft], transaction.pure.address('0xMyAddress'));
// ... sign and execute the transaction
}
```
Expand All @@ -135,9 +135,9 @@ Allows the parent holder to edit the setup (allow child creation and allow time
```js
const editSetup = async (name: stringify, parentNftId: string, allowChildCreation: boolean, allowTimeExtension: boolean) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// We build the transaction to edit the setup of a subname.
suinsTransaction.editSetup({
Expand All @@ -158,9 +158,9 @@ This functionality is available only if the parent allows time extension for the
```js
const extendExpiration = async (nftId: string, expirationMs: number) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// We build the transaction to extend the expiration of a subname.
suinsTransaction.extendExpiration({
Expand All @@ -179,9 +179,9 @@ Read more about the differences between a [subname and a leaf subname](../subnam
```js
const createLeafSubname = async (name: stringify, parentNftId: string, targetAddress: string) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// We build the transaction to create a leaf subname.
// A leaf subname is a subname that has a target address and no NFT of its own.
Expand All @@ -195,7 +195,7 @@ const createLeafSubname = async (name: stringify, parentNftId: string, targetAdd
});

// Transfer the NFT
transactionBlock.transferObjects([subNameNft], transactionBlock.pure.address('0xMyAddress'));
transaction.transferObjects([subNameNft], transaction.pure.address('0xMyAddress'));
// ... sign and execute the transaction
}
```
Expand All @@ -205,9 +205,9 @@ const createLeafSubname = async (name: stringify, parentNftId: string, targetAdd
```js
const removeLeafSubname = async (name: string, parentNftId: string) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// Build the transaction to remove a leaf subname.
suinsTxb.removeLeafSubName({
Expand All @@ -228,9 +228,9 @@ Currently supports AVATAR and IPFS hash.
```js
const setMetadata = async (nft: string, avatar: string, contentHash: string) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// Build the transaction to set the metadata.
// Set the avatar to the supplied value.
Expand All @@ -257,9 +257,9 @@ Allows burning an expired name to get back storage rebates.
```js
const burn = async (nftId: string) => {
// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// Build the transaction to burn the expired name.
suinsTransaction.burn({
Expand All @@ -284,9 +284,9 @@ const composedExample = async (name: string, years: number) => {
const priceList = await suinsClient.getPriceList();

// Create a transaction block as usual in your PTBs.
const transactionBlock = new TransactionBlock();
const transaction = new Transaction();
// Pass in the transaction block & the app's global SuinsClient.
const suinsTransaction = new SuinsTransaction(suinsClient, transactionBlock);
const suinsTransaction = new SuinsTransaction(suinsClient, transaction);

// Build the transaction to register the name.
const nft = suinsTransaction.register({
Expand All @@ -306,7 +306,7 @@ const composedExample = async (name: string, years: number) => {
suinsTransaction.setDefault(name);

// Transfer the name's NFT to the address.
transactionBlock.transferObjects([nft], transactionBlock.pure.address('0xMyAddress'));
transaction.transferObjects([nft], transaction.pure.address('0xMyAddress'));

// ... sign and execute the transaction
}
Expand Down
44 changes: 41 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"node": ">=16"
},
"dependencies": {
"@mysten/sui.js": "0.54.1"
"@mysten/sui": "^1.0.5"
},
"devDependencies": {
"@types/tmp": "^0.2.3",
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { normalizeSuiNSName } from '@mysten/sui.js/utils';
import { normalizeSuiNSName } from '@mysten/sui/utils';

export function isSubName(name: string): boolean {
return normalizeSuiNSName(name, 'dot').split('.').length > 2;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/suins-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import type { SuiClient } from '@mysten/sui.js/client';
import { isValidSuiNSName } from '@mysten/sui.js/utils';
import type { SuiClient } from '@mysten/sui/client';
import { isValidSuiNSName } from '@mysten/sui/utils';

import {
getConfigType,
Expand Down
Loading

0 comments on commit f537561

Please sign in to comment.