Skip to content

Commit

Permalink
doc: add docs for new api and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceeewong committed Jun 21, 2024
1 parent fc8036d commit a059d58
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 15 deletions.
42 changes: 38 additions & 4 deletions website/docs/Hooks/useWallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,27 @@ the [@mysten/wallet-standard](https://github.com/MystenLabs/sui/tree/main/sdk/wa
|----------------------------------| --------- |
| [IWalletAdapter](/docs/Types#IWalletAdapter) | undefined | undefined |

### signAndExecuteTransactionBlock
### signTransaction

The universal function to send and execute transactions via connected wallet.
The function is for transaction signing.

| Type | Default |
|--------------------------------------------------------------| ------- |
| `({transaction: Transaction}) => Promise<SignedTransaction>` | |


### signAndExecuteTransaction

This is a new API that implements the new recommended flow of signing, executing transactions and reporting the results to the connected wallet, which gives your DApp a fine-grained control for the execution and thus benefits the e2e latency and data consistency.

With this new feature, you can use the `signAndExecuteTransaction` method to sign transactions and have them executed by submitting signed transactions to the fullnode RPC with the control on your DApp side instead of the wallet side.

This is an enhanced API of `signAndExecuteTransactionBlock` where the comparison between the two APIs are shown in the table.

| API | Execution | FullNode for Execution | GraphQL API support |
|:-:|:-----------------:| :-: |:-------------------------------------------------------:|
| signAndExecuteTransactionBlock | on Wallet | Specified by Wallet | Depend on wallet's implementation |
| signAndExecuteTransaction | on DApp | Specified by DApp | Can be done by customizing the execute function |

| Type | Default |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------- |
Expand Down Expand Up @@ -321,9 +339,25 @@ All the wallet events:

## Deprecated API

### signAndExecuteTransaction
### signAndExecuteTransactionBlock

Deprecated, use [signAndExecuteTransactionBlock](#signandexecutetransactionblock) instead.
Deprecated, use [signAndExecuteTransaction](#signandexecutetransaction) instead.

The universal function to send and execute transactions via connected wallet.

| Type | Default |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------- |
| `({transactionBlock: Transaction, requestType?: ExecuteTransactionRequestType, options?: SuiTransactionBlockResponseOptions}) => Promise<SuiSignAndExecuteTransactionBlockOutput>` | |

### signTransactionBlock

Deprecated, use [signTransaction](#signtransaction) instead.

The function is for transaction signing.

| Type | Default |
|-------------------------------------------------------------------| ------- |
| `({transactionBlock: Transaction}) => Promise<SuiSignTransactionBlockOutput>` | |

### executeMoveCall and executeSerializedMoveCall

Expand Down
18 changes: 9 additions & 9 deletions website/docs/QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ yarn add @suiet/wallet-kit
pnpm install @suiet/wallet-kit
```

Next, make sure `@mysten/sui.js` is installed in your project. If not, install it as well.
Next, make sure `@mysten/sui` is installed in your project. If not, install it as well.

```shell
npm install @mysten/sui.js
npm install @mysten/sui
# or
yarn add @mysten/sui.js
yarn add @mysten/sui
# or
pnpm install @mysten/sui.js
pnpm install @mysten/sui
```

Then wrap your `<App />` with our context provider, so that our hooks can work nicely inside your dapp.
Expand Down Expand Up @@ -99,7 +99,7 @@ your dapp is already empowered and able to call wallet capabilities.🎉
```jsx
import {useWallet} from '@suiet/wallet-kit';
import {TransactionBlock} from "@mysten/sui.js";
import {Transaction} from "@mysten/sui/transactions";

const App = () => {
const wallet = useWallet()
Expand All @@ -113,14 +113,14 @@ const App = () => {

// launch a move call for the connected account via wallet
async function handleMoveCall() {
const tx = new TransactionBlock();
const tx = new Transaction();
const packageObjectId = "0x1";
tx.moveCall({
target: `${packageObjectId}::nft::mint`,
arguments: [tx.pure("Example NFT")],
arguments: [tx.pure.string("Example NFT")],
});
await wallet.signAndExecuteTransactionBlock({
transactionBlock: tx,
await wallet.signAndExecuteTransaction({
transaction: tx,
});
}

Expand Down
4 changes: 2 additions & 2 deletions website/docs/migration/upgradeTo0.2.x.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 1
sidebar_position: 998
---

# Upgrade to v0.2.x
Expand Down Expand Up @@ -140,4 +140,4 @@ The mysten wallet standard has been updated to version 0.5.0.

So make sure your wallet adapter supports it, otherwise our kit will not detect your wallet as valid ones.

For more of integration details, check out [How to integrate with Suiet Kit?](/docs/CanIUse#how-to-integrate-with-suiet-kit)
For more of integration details, check out [How to integrate with Suiet Kit?](/docs/CanIUse#how-to-integrate-with-suiet-kit)
95 changes: 95 additions & 0 deletions website/docs/migration/upgradeTo0.3.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
sidebar_position: 1
---

# Upgrade to v0.3.x

Hi developers, new upgrade is coming 📣 We are proud to announce the Suiet Wallet Kit v0.3.x release 🥳 This release includes several **exciting features**, **important improvements**, and unfortunately, some **breaking changes** as well 🥲 But don't worry, we have prepared a migration guide for you and your dapp to upgrade to this version smoothly ❤️

Due to the upgrade of [Sui Typescript SDK v1](https://sdk.mystenlabs.com/typescript), the new [Sui wallet standard](https://docs.sui.io/standards/wallet-standard), and the emergence of Sui [Stashed Wallet](https://getstashed.com/) with ZKSend, we are upgrading the Suiet Wallet Kit for DApps to catch up with these upgrades.

With the new wallet kit, your dapp can interact with all wallets in the Sui ecosystem via the latest wallet standard. Additionally, there are some breaking changes incurred by the upgrade of Sui Typescript SDK, please read the [migration section](/docs/migration/upgradeTo0.3.x#for-dapp-developers) for instructions.

Moreover, the wallet kit now enables your dapp to easily integrate with the Stashed Wallet built by the Mysten Lab that uses your social account like Google or Twitch to manage your crypto wallet. Please check this [documentation](/docs/tutorial/customize-wallet-list#add-stashed-wallet-new) for more information.


**We recommend all users to upgrade to this version 📣**

:::info
For more details of the migration guide to Sui Typescript SDK v1, check out the [Migration doc for Sui SDK v1](https://sdk.mystenlabs.com/typescript/migrations/sui-1.0)
:::

## For Dapp Developers

### [Major breaking change] - changing Sui SDK from `@mysten/sui.js` to `@mysten/sui`

Due to the upgrade and [renaming of the Sui Typescript SDK v1](https://sdk.mystenlabs.com/typescript/migrations/sui-1.0#changes-to-mystensui), our kit also changes the underlying dependency from `@mysten/sui.js` to `@mysten/sui`. This will ensure that the kit works correctly with the correct dependency.

```npm
npm uninstall @mysten/sui.js
npm install @mysten/sui
```

And then update all the imports in your code:

```diff
- import { SuiClient } from '@mysten/sui.js'
+ import { SuiClient } from '@mysten/sui'
```

### [Major breaking change] - Changing TransactionBlock to Transaction

The TransactionBlock class has been renamed to Transaction according to the Sui Typescript SDK.

:::info
We are only showing an example of renaming here, but for more API changes related to this, please refer to [the migration doc of Sui Typescript SDK](https://sdk.mystenlabs.com/typescript/migrations/sui-1.0#transaction).
:::

```diff
- import {TransactionBlock} from '@mysten/sui.js/transactions'
+ import {Transaction} from '@mysten/sui/transactions'
```

### [Recommendation] A New Way of Sign and Execute Transaction for your DApp

There is a new recommended way for DApp developer to build things in a way that will work best with wallets as the ecosystem migrates towards [GraphQL](https://sdk.mystenlabs.com/typescript/graphql) and indexer backed APIs. Please refer to the tutorial [Sign and Execute Transactions](/docs/tutorial/sign-and-execute-transactions) for more information.

Fortunately, our wallet kit has integrated the above workflow for dapp developers in the new API `signAndExecuteTransaction` of the useWallet hook. Check the [API Reference](/docs/Hooks/useWallet#signandexecutetransaction) for more information.

### [New feature] - signAndExecuteTransaction in useWallet

This is a new API that implements the new recommended flow of signing, executing transactions and reporting the results to the connected wallet, which gives your DApp a fine-grained control for the execution and thus benefits the e2e latency and data consistency.

With this new feature, you can use the `signAndExecuteTransaction` method to sign transactions and have them executed by submitting signed transactions to the fullnode RPC with the control on your DApp side instead of the wallet side. Detail description is in the [API Reference](/docs/Hooks/useWallet#signandexecutetransaction) .

This is an enhanced API of `signAndExecuteTransactionBlock` where the comparison between the two APIs are shown in the [table](/docs/tutorial/sign-and-execute-transactions#api-comparison).

### [New feature] - signTransaction in useWallet

This feature allows you to sign transactions and get the signature using the `signTransaction` method. It's a renaming API from [signTransactionBlock](/docs/Hooks/useWallet#signtransactionblock). Check [API Reference](/docs/Hooks/useWallet#signtransaction).

### [New feature] - Integration with Stashed Wallet

The new wallet kit now supports integration with Stashed Wallet, enabling users to manage their crypto wallets using their social accounts. Please refer to [this section](/docs/tutorial/customize-wallet-list#add-stashed-wallet-new) for integration.

### [Deprecated] - signAndExecuteTransactionBlock in useWallet

The `signAndExecuteTransactionBlock` method has been deprecated and replaced with `signAndExecuteTransaction`. Check [API Reference](/docs/Hooks/useWallet#signtransactionblock).

### [Deprecated] - signTransactionBlock in useWallet

The `signTransactionBlock` method has been deprecated and replaced with `signTransaction`. Check [API Reference](/docs/Hooks/useWallet#signtransaction).

## For Wallet Developer

### [Mandatory] implementing sui:signTransaction and sui:signAndExecuteTransaction

Starting from the wallet standard vXX, the new API `sui:signTransaction` and `sui:signAndExecuteTransaction` are required for enabling the new flow of signing and executing transactions and the replacement of `sui:signTransaction` and `sui:signAndExecuteTransaction` respectively.

:::info
Although the wallet kit will handle the calling for 'sui:signTransaction' vs 'sui:signTransactionBlock', and 'sui:signAndExecuteTransaction' vs 'sui:signAndExecuteTransactionBlock' based on which wallet-standard APIs that are implemented on the target wallet, it is still recommended to implement the new wallet standard APIs as soon as possible for future.
:::

### [Optional] implementing sui:reportWalletEffect

The sui:reportWalletEffect is meant for wallet to cache the transaction execution response reported by DApps since the new flow of execution is performed on the DApp side. It's an optional implementation for now. Please refer to the wallet standard document for more information.
57 changes: 57 additions & 0 deletions website/docs/tutorial/sign-and-execute-transactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
sidebar_position: 1
---

# Sign and Execute Transactions

There is a new recommended way for DApp developer to build things in a way that will work best with wallets as the ecosystem migrates towards [GraphQL](/) and indexer backed APIs.

The current recommended way to execute transactions for dApps is as follows:

1. The dapp constructs transaction using the [Transaction builder API](https://sdk.mystenlabs.com/typescript/transaction-building/basics)
2. The dapp signs the transaction using the new `sui:signTransaction` feature
1. The wallet kit manages calling either sui:signTransaction or sui:signTransactionBlock depending on which API is implemented in the wallet
3. The dapp executes the transaction using it's own RPC provider (can be either GraphQL, or JSON rpc)
1. It's the key different from the previous workflow where the transactions are executed on the wallet's specified RPC which might increase the e2e latency and incur data inconsistency between fullnodes due to synchronization.
4. The dapp invokes the `sui:reportTransactionEffects` feature with the effects after the transaction is successfully executed.
1. The sui:reportTransactionEffects allows wallets to cache the effects of transactions, enabling transaction building to continue to work, even if the wallets RPC node has not indexed a previous transaction.

This flow enables dapps to have the best possible e2e latency when executing transactions, and enables dapps to query for whatever data you need in response of the execution request.

# Implementation

To implement the above flow, there are two options.

The first option is to use the [signAndExecuteTransaction](/) API from the [useWallet](/) hook.

By default, the API will use the same RPC URL of the current [chain](/) used by your dapp.

> For more info about configuration of Chain for your DApp, please check the [Turorial: Configure supported chains (networks)](/docs/tutorial/configure-chain).
```tsx
// assuming in your React component.
import {Transaction} from '@mysten/sui/transactions'

function App() {
async function performTransaction() {
const transaction = new Transaction()
// contruct your transaction using the Transaction builder API mentioned above
// pass the transaction to signAndExecuteTransaction
const resData = await wallet.signAndExecuteTransaction({
transaction: transaction,
});
// deal with the response
}
}
```



## API Comparison

Differences between signAndExecuteTransactionBlock and signAndExecuteTransaction are shown below:

| API | Execution | FullNode for Execution | GraphQL API support |
|:-:|:-----------------:| :-: |:-------------------------------------------------------:|
| signAndExecuteTransactionBlock | on Wallet | Specified by Wallet | Depend on wallet's implementation |
| signAndExecuteTransaction | on DApp | Specified by DApp | Can be done by customizing the execute function |

0 comments on commit a059d58

Please sign in to comment.