-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add wallet inegrate * fix * update * update * update * update * translate
- Loading branch information
1 parent
409de31
commit ec54d2f
Showing
2 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
docs/website/pages/build/sdk/wallet-integrate.en-US.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# Wallet integration | ||
|
||
This document will introduce how to integrate Rooch's wallet functions (query, transfer) into wallets, asset browsers, aggregators and other applications, and will introduce the TS SDK methods provided by Rooch to wallet developers. | ||
|
||
## Client operations | ||
|
||
`useRoochClientQuery` provides an encapsulation for calling RPC methods. After passing the RPC method name and parameter list, the return result is processed. For details about which RPC methods, parameters and return results can be passed, please refer to [Rooch JSON RPC](https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/rooch-network/rooch/main/crates/rooch-open-rpc-spec/schemas/openrpc.json). | ||
|
||
```ts | ||
export declare function useRoochClientQuery<T extends keyof RpcMethods, TData = RpcMethods[T]['result']>(...args: undefined extends RpcMethods[T]['params'] ? [method: T, params?: RpcMethods[T]['params'], options?: UseRoochClientQueryOptions<T, TData>] : [method: T, params: RpcMethods[T]['params'], options?: UseRoochClientQueryOptions<T, TData>]): UseQueryResult<TData, Error>; | ||
``` | ||
|
||
Here are some examples of calls: | ||
|
||
- Example of calling the `rooch_getBlances` method: | ||
|
||
```tsx | ||
const { | ||
data: assetsList, | ||
isPending, | ||
refetch: refetchAssetsList, | ||
} = useRoochClientQuery( | ||
'getBalances', | ||
{ | ||
owner: BitcoinAddressToRoochAddress(address).toHexAddress(), | ||
}, | ||
{ refetchInterval: 5000 } | ||
); | ||
``` | ||
|
||
- Example of calling `btc_queryUTXOs` method: | ||
|
||
```tsx | ||
const { data: utxoList, isPending: isUTXOPending } = useRoochClientQuery( | ||
'queryUTXO', | ||
{ | ||
filter: { | ||
owner: address, | ||
}, | ||
cursor: queryOptions.cursor, | ||
limit: queryOptions.pageSize, | ||
}, | ||
{ enabled: !!address } | ||
); | ||
``` | ||
|
||
## Account related | ||
|
||
### Get session key | ||
|
||
```ts | ||
export declare function useCurrentSession(): import("@roochnetwork/rooch-sdk").Session | null; | ||
``` | ||
|
||
Example: | ||
|
||
```ts | ||
import { useCurrentSession } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
const sessionKey = useCurrentSession(); | ||
``` | ||
|
||
### Get current address | ||
|
||
```ts | ||
import { useCurrentAddress } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
const address = useCurrentAddress(); | ||
``` | ||
|
||
## Network switching | ||
|
||
For network switching, use the `useSwitchNetwork` method, passing the following parameters: | ||
|
||
```ts | ||
type UseSwitchNetworkArgs = string; | ||
``` | ||
|
||
If you are connected to the network, you can use the `useCurrentNetwork` method. | ||
|
||
## Get context | ||
|
||
The `useRoochContext` method is used to obtain the context. The context information is as follows: | ||
|
||
```ts | ||
export interface ClientProviderContext { | ||
client: RoochClient; | ||
networks: NetworkConfigs; | ||
network: NetworkType; | ||
config: NetworkConfig | null; | ||
selectNetwork: (network: string) => void; | ||
} | ||
``` | ||
|
||
## Send transaction | ||
|
||
`UseSignAndExecuteTransaction` method, to execute signed transactions, needs to pass the following parameters: | ||
|
||
```ts | ||
type UseSignAndExecuteTransactionArgs = { | ||
transaction: Transaction; | ||
signer?: Signer; | ||
}; | ||
``` | ||
|
||
## Transfer | ||
|
||
### Coin | ||
|
||
```ts | ||
export declare function useTransferCoin({ mutationKey, ...mutationOptions }?: UseSwitchNetworkMutationOptions): UseMutationResult<UseTransferCoinResult, Error, UseTransferCoinArgs, unknown>; | ||
``` | ||
|
||
- For transfer transactions, you can use the `useTransferCoin` method, passing the following parameters: | ||
|
||
```ts | ||
type UseTransferCoinArgs = { | ||
signer?: Signer; | ||
recipient: address; | ||
amount: number | bigint; | ||
coinType: TypeArgs; | ||
}; | ||
``` | ||
|
||
### Object | ||
|
||
For object transfer, you can use the `useTransferObject` method, passing the following parameters: | ||
|
||
```ts | ||
type UseTransferObjectArgs = { | ||
signer: Signer; | ||
recipient: string; | ||
objectId: string; | ||
objectType: TypeArgs; | ||
}; | ||
``` | ||
|
||
## Integrate wallet functionality into Rooch SDK | ||
|
||
Rooch currently provides a set of TypeScript SDKs, providing a convenient development experience for Rooch developers or application developers. | ||
|
||
### Introduce | ||
|
||
`rooch-sdk` provides some basic encapsulation, while `rooch-sdk-kit` provides more practical development tools for application development. Wallet integration uses these tools. The relevant code is stored in the `rooch` repo. The detailed path is: | ||
|
||
``` | ||
rooch/sdk/typescript/rooch-sdk-kit/src/wellet | ||
``` | ||
|
||
### How to integrate a wallet into Rooch | ||
|
||
At present, Rooch has integrated `UniSat`, `OneKey` and `OKX`. If the wallet manufacturer needs to integrate the wallet into Rooch, it needs to use the SDK to do some corresponding development and submit the code for wallet integration to the above directory. | ||
|
||
Assets created on Rooch only need to call a `getBalance` interface. | ||
|
||
Taking UniSat as an example, apart from some code development related to operating connections, the final asset must be displayed. The most critical thing is this code: | ||
|
||
```ts | ||
getBalance(): Promise<{ confirmed: number; unconfirmed: number; total: string }> { | ||
return this.getTarget().getBalance() | ||
} | ||
``` |
162 changes: 162 additions & 0 deletions
162
docs/website/pages/build/sdk/wallet-integrate.zh-CN.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# 钱包集成 | ||
|
||
这篇文档将介绍如何将 Rooch 的钱包功能(查询、转账)集成到钱包、资产浏览器、聚合器等应用中,将向钱包开发者介绍 Rooch 提供的 TS SDK 方法。 | ||
|
||
## 客户端操作 | ||
|
||
`useRoochClientQuery` 提供了调用 RPC 方法的封装,传递 RPC 方法名和参数列表后对返回结果进行处理,具体可以传递哪些 RPC 方法、参数以及返回结果,请参考 [Rooch JSON RPC](https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/rooch-network/rooch/main/crates/rooch-open-rpc-spec/schemas/openrpc.json)。 | ||
|
||
```ts | ||
export declare function useRoochClientQuery<T extends keyof RpcMethods, TData = RpcMethods[T]['result']>(...args: undefined extends RpcMethods[T]['params'] ? [method: T, params?: RpcMethods[T]['params'], options?: UseRoochClientQueryOptions<T, TData>] : [method: T, params: RpcMethods[T]['params'], options?: UseRoochClientQueryOptions<T, TData>]): UseQueryResult<TData, Error>; | ||
``` | ||
|
||
接下来会举几个调用例子: | ||
|
||
- 调用 `rooch_getBlances` 方法的例子: | ||
|
||
```tsx | ||
const { | ||
data: assetsList, | ||
isPending, | ||
refetch: refetchAssetsList, | ||
} = useRoochClientQuery( | ||
'getBalances', | ||
{ | ||
owner: BitcoinAddressToRoochAddress(address).toHexAddress(), | ||
}, | ||
{ refetchInterval: 5000 } | ||
); | ||
``` | ||
|
||
- 调用 `btc_queryUTXOs` 方法的例子: | ||
|
||
```tsx | ||
const { data: utxoList, isPending: isUTXOPending } = useRoochClientQuery( | ||
'queryUTXO', | ||
{ | ||
filter: { | ||
owner: address, | ||
}, | ||
cursor: queryOptions.cursor, | ||
limit: queryOptions.pageSize, | ||
}, | ||
{ enabled: !!address } | ||
); | ||
``` | ||
|
||
## 账户相关 | ||
|
||
### 获取 Session Key | ||
|
||
```ts | ||
export declare function useCurrentSession(): import("@roochnetwork/rooch-sdk").Session | null; | ||
``` | ||
|
||
例子: | ||
|
||
```ts | ||
import { useCurrentSession } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
const sessionKey = useCurrentSession(); | ||
``` | ||
|
||
### 获取当前地址 | ||
|
||
```ts | ||
import { useCurrentAddress } from '@roochnetwork/rooch-sdk-kit'; | ||
|
||
const address = useCurrentAddress(); | ||
``` | ||
|
||
## 网络切换 | ||
|
||
对于网络切换可以使用 `useSwitchNetwork` 方法,传递以下参数: | ||
|
||
```ts | ||
type UseSwitchNetworkArgs = string; | ||
``` | ||
|
||
如果已连接网路,可以使用 `useCurrentNetwork` 方法。 | ||
|
||
## 获取上下文 | ||
|
||
`useRoochContext` 方法用于获取上下文,上下文信息如下所示: | ||
|
||
```ts | ||
export interface ClientProviderContext { | ||
client: RoochClient; | ||
networks: NetworkConfigs; | ||
network: NetworkType; | ||
config: NetworkConfig | null; | ||
selectNetwork: (network: string) => void; | ||
} | ||
``` | ||
|
||
## 发送交易 | ||
|
||
`UseSignAndExecuteTransaction` 方法,执行签名交易,需要传递以下参数: | ||
|
||
```ts | ||
type UseSignAndExecuteTransactionArgs = { | ||
transaction: Transaction; | ||
signer?: Signer; | ||
}; | ||
``` | ||
|
||
## 转账 | ||
|
||
### Coin | ||
|
||
```ts | ||
export declare function useTransferCoin({ mutationKey, ...mutationOptions }?: UseSwitchNetworkMutationOptions): UseMutationResult<UseTransferCoinResult, Error, UseTransferCoinArgs, unknown>; | ||
``` | ||
|
||
- 对于转账交易可以使用 `useTransferCoin` 方法,传递以下参数: | ||
|
||
```ts | ||
type UseTransferCoinArgs = { | ||
signer?: Signer; | ||
recipient: address; | ||
amount: number | bigint; | ||
coinType: TypeArgs; | ||
}; | ||
``` | ||
|
||
### Object | ||
|
||
- 对于对象的转移可以使用 `useTransferObject` 方法,传递以下参数: | ||
|
||
```ts | ||
type UseTransferObjectArgs = { | ||
signer: Signer; | ||
recipient: string; | ||
objectId: string; | ||
objectType: TypeArgs; | ||
}; | ||
``` | ||
|
||
## 将钱包功能集成到 Rooch SDK 中 | ||
|
||
Rooch 目前提供了一套 TypeScript 的 SDK,为 Rooch 开发者或应用开发者提供了便捷的开发体验。 | ||
|
||
### 介绍 | ||
|
||
`rooch-sdk` 提供了一些基础的封装,`rooch-sdk-kit` 则为应用开发提供了更实用的开发工具。而钱包集成就用到了这些工具,相关代码存放在 `rooch` 仓库中,详细路径为: | ||
|
||
``` | ||
rooch/sdk/typescript/rooch-sdk-kit/src/wellet | ||
``` | ||
|
||
### 如何集成钱包到 Rooch 中 | ||
|
||
目前 Rooch 已经集成了 `UniSat`、`OneKey` 和 `OKX`,如果钱包厂商需要集成钱包到 Rooch 中,则需要使用 SDK 做一些相应的开发,并将实现钱包集成的代码,提交到上述目录中。 | ||
|
||
在 Rooch 上创建的资产只需要通过调用一个 `getBalance` 接口即可。 | ||
|
||
以 UniSat 为例,除去一些操作连接相关的代码开发外,最终要显示资产,最关键的是这段代码: | ||
|
||
```ts | ||
getBalance(): Promise<{ confirmed: number; unconfirmed: number; total: string }> { | ||
return this.getTarget().getBalance() | ||
} | ||
``` |