Skip to content

Standard features

namesupported
connect
disconnect
signPersonalMessage
signMessage
signTransaction
signTransactionBlock
signAndExecuteTransaction
signAndExecuteTransactionBlock

Wallet Standard Features

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]

Usage

js
	provider.connect()
	provider.connect()

connect

Used to initiate a connection with the wallet.

Account

AttributeTypeDescription
addressstringcurrent address
chains string[]The Sui blockchain we are integrated with
features string[]Which capabilities defined by the Sui standards we have implemented
icon anysui standard output
label anywallet name

Returns:

Promose<object>

Property NameTypeDescription
accountsAccount[]account list conneced in sui chian defined above
js
await provider.connect();
await provider.connect();

disconnect

Disconnect wallet.

js
await provider.disconnect();
await provider.disconnect();

SignPersonalMessage & SignMessage

Used to prompt the user to sign a personal message and return the signed message to the dApp. This is used to verify the user's public key. if you use @mysten/sui < 1.0, please use signMessage, otherwise use signPersonalMessage instead

Parameters

<object>

Property NameTypeDescription
messageUint8ArrayThe message to be signed

Returns:

Promise<object>

Property NameTypeDescription
bytesstringThe signed message in base64 format.
signaturestringThe digital signature.

Usage

js
const msg = 'Hello Bitget Wallet!'
const msgBytes = new TextEncoder().encode(msg)
const { signature, messageBytes } = await provider.signPersonalMessage({ 
	message: msgBytes 
})
const msg = 'Hello Bitget Wallet!'
const msgBytes = new TextEncoder().encode(msg)
const { signature, messageBytes } = await provider.signPersonalMessage({ 
	message: msgBytes 
})
js
const msg = 'Hello Bitget Wallet!'
const msgBytes = new TextEncoder().encode(msg)
const { signature, messageBytes } = await provider.signMessage({ 
	message: msgBytes
})
const msg = 'Hello Bitget Wallet!'
const msgBytes = new TextEncoder().encode(msg)
const { signature, messageBytes } = await provider.signMessage({ 
	message: msgBytes
})

signTransaction & signTransactionBlock

Used to prompt the user to sign a personal message and return the signed message to the dApp. This is used to verify the user's public key. if you use @mysten/sui < 1.0, please use signTransaction, otherwise use signTransactionBlock instead

Parameters

  • transaction instance defined by @mysten/sui or @mysten/sui.js
ts
// import {Transaction} from "@mysten/sui/transactions";
interface signTransactionInput {
	transaction: Transaction
}
// import {Transaction} from "@mysten/sui/transactions";
interface signTransactionInput {
	transaction: Transaction
}
ts
// import {TransactionBlock} from "@mysten/sui.js/transactions";
interface signTransactionBlockInput {
	transactionBlock: TransactionBlock
}
// import {TransactionBlock} from "@mysten/sui.js/transactions";
interface signTransactionBlockInput {
	transactionBlock: TransactionBlock
}

Returns

Promise<object>

Property NameTypeDescription
bytesstringThe signed message in base64 format.
signaturestringThe digital signature.

Usage

js
import {Transaction} from "@mysten/sui/transactions";
const address =  window.bitkeep.suiWallet.account.address
tx.setSender(address)
tx.setGasBudget(100000)
const [coin] = tx.splitCoins({GasCoin: true}, [BigInt(this.amount)])
tx.transferObjects([coin], this.toAddress);
const feature = provider.features['sui:signTransaction'].signTransaction;
const signature = await feature({transaction: tx})
import {Transaction} from "@mysten/sui/transactions";
const address =  window.bitkeep.suiWallet.account.address
tx.setSender(address)
tx.setGasBudget(100000)
const [coin] = tx.splitCoins({GasCoin: true}, [BigInt(this.amount)])
tx.transferObjects([coin], this.toAddress);
const feature = provider.features['sui:signTransaction'].signTransaction;
const signature = await feature({transaction: tx})
js
import {TransactionBlock} from "@mysten/sui.js/transactions";
const address =  window.bitkeep.suiWallet.account.address
tx.setSender(address)
tx.setGasBudget(100000)
const [coin] = tx.splitCoins(tx.gas, [tx.pure(amountMIST)]);
tx.transferObjects([coin], tx.pure(to.address));
const feature = provider.features['sui:signTransactionBlock'].signTransactionBlock;
const signature = await feature.signTransactionBlock(txBytes)
import {TransactionBlock} from "@mysten/sui.js/transactions";
const address =  window.bitkeep.suiWallet.account.address
tx.setSender(address)
tx.setGasBudget(100000)
const [coin] = tx.splitCoins(tx.gas, [tx.pure(amountMIST)]);
tx.transferObjects([coin], tx.pure(to.address));
const feature = provider.features['sui:signTransactionBlock'].signTransactionBlock;
const signature = await feature.signTransactionBlock(txBytes)

BrocastTransaction

use signAndExecuteTransaction or signAndExecuteTransactionBlock to sign and brocast transaction

WARNING

  • the input and output types are identical to signTransaction.
  • only difference is that this function broadcasts the transaction after signing.

Dapp Demo

transfer coin

vue
<template>
  <div>
    <button class="bitget-btn" @click="connect">{{address ? 'connected' : 'connect'}}</button>&nbsp;
    <input class="bigtet-input" placeholder="amount" v-model="amount"/>&nbsp;
    <input class="bigtet-input" placeholder="address" v-model="toAddress"/>&nbsp;
    <button class="bitget-btn" @click="run">send</button>
  </div>
</template>
<script >
  import {Transaction} from "@mysten/sui/transactions";
  export default {
    data(){
      return {
        amount: 0,
        toAddress: '0x',
        address: false
      }
    },
    async mounted(){
      this.address = await window.bitkeep.suiWallet.isConnected()
    },
    methods:{
      async connect(){
        await window.bitkeep.suiWallet.connect()
        this.address = window.bitkeep.suiWallet.account.address
      },
      async run(){
        const tx = new Transaction()
        const address =  window.bitkeep.suiWallet.account.address
        tx.setSender(address)
        tx.setGasBudget(100000)
        const [coin] = tx.splitCoins({GasCoin: true}, [BigInt(this.amount)])
        tx.transferObjects([coin], this.toAddress);
        const res = window.bitkeep.suiWallet.signTransaction({transaction: tx})
        return res
      }
    }
  }
</script>
<template>
  <div>
    <button class="bitget-btn" @click="connect">{{address ? 'connected' : 'connect'}}</button>&nbsp;
    <input class="bigtet-input" placeholder="amount" v-model="amount"/>&nbsp;
    <input class="bigtet-input" placeholder="address" v-model="toAddress"/>&nbsp;
    <button class="bitget-btn" @click="run">send</button>
  </div>
</template>
<script >
  import {Transaction} from "@mysten/sui/transactions";
  export default {
    data(){
      return {
        amount: 0,
        toAddress: '0x',
        address: false
      }
    },
    async mounted(){
      this.address = await window.bitkeep.suiWallet.isConnected()
    },
    methods:{
      async connect(){
        await window.bitkeep.suiWallet.connect()
        this.address = window.bitkeep.suiWallet.account.address
      },
      async run(){
        const tx = new Transaction()
        const address =  window.bitkeep.suiWallet.account.address
        tx.setSender(address)
        tx.setGasBudget(100000)
        const [coin] = tx.splitCoins({GasCoin: true}, [BigInt(this.amount)])
        tx.transferObjects([coin], this.toAddress);
        const res = window.bitkeep.suiWallet.signTransaction({transaction: tx})
        return res
      }
    }
  }
</script>

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));

Reference Documentation

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