Skip to content

Sui

Bitget Wallet supports this feature only in the following versions

PlatformVersionDescription
Chrome Extension>=v1.4.6mainnet
App(iOS)>=v7.3.4mainnet
App(Android)>=v7.3.4mainnet

Get provider

The Sui wallet is based on wallet-standard. Unlike other heterogeneous chains, the provider is obtained through events.

js
const chainName = 'suiMainnet';
const GlobalWallet = {
    register: (wallet) => {
        GlobalWallet[chainName] = wallet
    }
}
const event = new CustomEvent('wallet-standard:app-ready', { detail: GlobalWallet });
window.dispatchEvent(event);

const provider = GlobalWallet[chainName]
const chainName = 'suiMainnet';
const GlobalWallet = {
    register: (wallet) => {
        GlobalWallet[chainName] = wallet
    }
}
const event = new CustomEvent('wallet-standard:app-ready', { detail: GlobalWallet });
window.dispatchEvent(event);

const provider = GlobalWallet[chainName]

connect

Connect the wallet

js
await provider.features['standard:connect'].connect();
await provider.features['standard:connect'].connect();

account

Get the wallet account address

js
const accounts = provider.account

accounts = [account, account, account]

// Data format
account = {
  address: '0x,,,,,,,,,,,,,,b1c',
  chains: ['sui:mainet']
};
const accounts = provider.account

accounts = [account, account, account]

// Data format
account = {
  address: '0x,,,,,,,,,,,,,,b1c',
  chains: ['sui:mainet']
};

standard:events

Event listener

js
let on = provider.features['standard:events'].on;

on("connect", (event) => console.log("sui connected.", event));
on("disconnect", (event) => console.log("sui disconnect.", event));
on("accountChanged", (event) => console.log("sui accountChanged.", event));
let on = provider.features['standard:events'].on;

on("connect", (event) => console.log("sui connected.", event));
on("disconnect", (event) => console.log("sui disconnect.", event));
on("accountChanged", (event) => console.log("sui accountChanged.", event));

signTransactionBlock

Sign a transaction

provider.features['sui:signTransactionBlock'].signTransactionBlock

js
// https://docs.sui.io/guides/developer/sui-101/building-ptb

import { TransactionBlock } from "@mysten/sui.js/transactions"; 
const tx = new TransactionBlock();
tx.moveCall({
  target: 'xxx',
  arguments: [
    tx.pure('Bitget'),
    tx.pure('wallet'),
  ],
});
const input = {
  transactionBlockSerialized: tx.serialize(),
  options: {
    showEffects: true,
  }
}

const signTransactionBlock = provider.features['sui:signTransactionBlock'].signTransactionBlock;
const transaction = await signTransactionBlock({ transactionBlock: tx })
// https://docs.sui.io/guides/developer/sui-101/building-ptb

import { TransactionBlock } from "@mysten/sui.js/transactions"; 
const tx = new TransactionBlock();
tx.moveCall({
  target: 'xxx',
  arguments: [
    tx.pure('Bitget'),
    tx.pure('wallet'),
  ],
});
const input = {
  transactionBlockSerialized: tx.serialize(),
  options: {
    showEffects: true,
  }
}

const signTransactionBlock = provider.features['sui:signTransactionBlock'].signTransactionBlock;
const transaction = await signTransactionBlock({ transactionBlock: tx })

signAndExecuteTransactionBlock

Sign and broadcast a transaction

provider.features['sui:signAndExecuteTransactionBlock'].signAndExecuteTransactionBlock

js
import { TransactionBlock } from "@mysten/sui.js/transactions";

const handleTransaction = async () => {
    const tx = new TransactionBlock()
    tx.moveCall({
      target: `${packageId}::${moduleName}::${functionName}`,
      arguments: [
        tx.pure(params1),
        tx.pure(params2),
      ],
      typeArguments: [],
    })
    const signAndExecuteTransactionBlock = provider.features['sui:signAndExecuteTransactionBlock'].signAndExecuteTransactionBlock;
    const result = await signAndExecuteTransactionBlock({
      transactionBlock: tx,
      options: { showEffects: true },
    })
    console.log('result', result)
    // Get the transaction status through result?.effects?.status?.status, 'success' for success and 'failure' for failure
}
import { TransactionBlock } from "@mysten/sui.js/transactions";

const handleTransaction = async () => {
    const tx = new TransactionBlock()
    tx.moveCall({
      target: `${packageId}::${moduleName}::${functionName}`,
      arguments: [
        tx.pure(params1),
        tx.pure(params2),
      ],
      typeArguments: [],
    })
    const signAndExecuteTransactionBlock = provider.features['sui:signAndExecuteTransactionBlock'].signAndExecuteTransactionBlock;
    const result = await signAndExecuteTransactionBlock({
      transactionBlock: tx,
      options: { showEffects: true },
    })
    console.log('result', result)
    // Get the transaction status through result?.effects?.status?.status, 'success' for success and 'failure' for failure
}

signMessage

Sign a message for a single transaction

Here, TextEncoder is used to handle UTF-8 bytes.

js
const msg = 'Hello Bitget Wallet!'
const msgBytes = new TextEncoder().encode(msg)
      
// const message = ethers.utils.toUtf8Bytes('bitget')

const signMessage = suiWallet.features['sui:signMessage'].signMessage;
const { signature, messageBytes } = await signMessage({ message: msgBytes })
const msg = 'Hello Bitget Wallet!'
const msgBytes = new TextEncoder().encode(msg)
      
// const message = ethers.utils.toUtf8Bytes('bitget')

const signMessage = suiWallet.features['sui:signMessage'].signMessage;
const { signature, messageBytes } = await signMessage({ message: msgBytes })

Reference Documentation

  1. Sui Official Documentation
  2. Wallet Standard
  3. TextEncoder