> For the complete documentation index, see [llms.txt](https://help.tokenpocket.pro/developer-en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.tokenpocket.pro/developer-en/extension-wallet/api-reference/sui-provider-api.md).

# Sui Provider API

TokenPocket Extension injects a Sui Provider into the page and supports Sui Wallet Standard. Developers can integrate Sui wallet capabilities through the Provider object or directly through Wallet Standard features.

## Provider Injection

The following objects are available on the page:

```ts
window.sui
window.tokenpocket.sui
```

TokenPocket also supports Sui Wallet Standard and can be discovered by standard wallet discovery flows.

## Quick Start

### Connect Wallet

```ts
const res = await window.sui.features['standard:connect'].connect();
console.log(res.accounts);
```

### Sign a Personal Message

```ts
const account = (await window.sui.features['standard:connect'].connect()).accounts[0];

const res =
  await window.sui.features['sui:signPersonalMessage'].signPersonalMessage({
    account,
    message: new TextEncoder().encode('hello tokenpocket'),
  });

console.log(res);
```

## API List

Sui capabilities are mainly exposed through Wallet Standard features.

### standard:connect

Connects the current site to a Sui account.

```ts
connect(): Promise<{
  accounts: ReadonlyWalletAccount[];
}>
```

Notes:

* The returned account object includes address, public key, chain information, and supported features.

### sui:signTransactionBlock

Signs a `TransactionBlock`.

```ts
signTransactionBlock(input: {
  account: ReadonlyWalletAccount;
  chain?: string;
  transactionBlock: any;
}): Promise<any>
```

### sui:signTransaction

Signs a transaction without broadcasting it.

```ts
signTransaction(input: {
  account: ReadonlyWalletAccount;
  chain?: string;
  transaction: any;
}): Promise<{
  bytes: string;
  signature: string;
}>
```

Notes:

* The current response is normalized to `bytes` and `signature`.

### sui:signAndExecuteTransactionBlock

Signs and executes a `TransactionBlock`.

```ts
signAndExecuteTransactionBlock(input: {
  account: ReadonlyWalletAccount;
  chain?: string;
  transactionBlock: any;
  options?: Record<string, any>;
}): Promise<any>
```

### sui:signAndExecuteTransaction

Signs and executes a transaction.

```ts
signAndExecuteTransaction(input: {
  account: ReadonlyWalletAccount;
  chain?: string;
  transaction: any;
  options?: Record<string, any>;
}): Promise<{
  bytes: string;
  signature: string;
  digest: string;
  effects: any;
}>
```

Notes:

* The current response is normalized to `bytes`, `signature`, `digest`, and `effects`.

### sui:signPersonalMessage

Signs a personal message.

```ts
signPersonalMessage(input: {
  account: ReadonlyWalletAccount;
  message: Uint8Array;
}): Promise<any>
```

Notes:

* Both the raw bytes and a UTF-8 string representation are provided to the wallet confirmation flow.

### sui:reportTransactionEffects

Reports transaction effects.

```ts
reportTransactionEffects(input: any): Promise<void>
```

Notes:

* The current implementation is callable but does not return additional data.

## Wallet Standard

TokenPocket currently supports these Sui Wallet Standard features:

* `standard:connect`
* `standard:events`
* `sui:signPersonalMessage`
* `sui:signTransactionBlock`
* `sui:signTransaction`
* `sui:signAndExecuteTransactionBlock`
* `sui:signAndExecuteTransaction`
* `sui:reportTransactionEffects`

Official references:

* [Wallet Standard docs](https://wallet-standard.github.io/wallet-standard/)
* [Sui Wallet Standard docs](https://docs.sui.io/onchain-finance/asset-custody/wallets/wallet-standard)

Supported chains:

```ts
['sui:mainnet']
```

### Integration Example

```ts
const wallet = window.sui;
const { accounts } = await wallet.features['standard:connect'].connect();
const account = accounts[0];

const result =
  await wallet.features['sui:signTransaction'].signTransaction({
    account,
    chain: 'sui:mainnet',
    transaction,
  });

console.log(result.bytes);
console.log(result.signature);
```

{% hint style="info" %}
For new dApps, it is recommended to integrate through Wallet Standard features instead of assuming private wallet-specific APIs.
{% endhint %}

## Error Handling

Use `try/catch` for all Provider calls.

```ts
try {
  const { accounts } = await window.sui.features['standard:connect'].connect();
  console.log(accounts[0].address);
} catch (error) {
  console.error(error);
}
```

Common failure cases:

* User rejects the connection request.
* User rejects signing or execution.
* Transaction input is missing or invalid.
* The current site is not authorized.

## Compatibility Notes

* TokenPocket exposes both `window.sui` and `window.tokenpocket.sui`.
* Wallet Standard is recommended for new integrations.
* Current chain support is based on `sui:mainnet`.
