Standard features
name | supported |
---|---|
connect | ✅ |
disconnect | ✅ |
signPersonalMessage | ✅ |
signMessage | ✅ |
signTransaction | ✅ |
signTransactionBlock | ✅ |
signAndExecuteTransaction | ✅ |
signAndExecuteTransactionBlock | ✅ |
provider
The Sui wallet is based on wallet-standard. Unlike other heterogeneous chains, the provider is obtained through events.
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
provider.connect()
provider.connect()
connect
Used to initiate a connection with the wallet.
Account
Attribute | Type | Description |
---|---|---|
address | string | current address |
chains | string[] | The Sui blockchain we are integrated with |
features | string[] | Which capabilities defined by the Sui standards we have implemented |
icon | any | sui standard output |
label | any | wallet name |
Returns:
Promose<object>
Property Name | Type | Description |
---|---|---|
accounts | Account[] | account list conneced in sui chian defined above |
await provider.connect();
await provider.connect();
disconnect
Disconnect wallet.
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 Name | Type | Description |
---|---|---|
message | Uint8Array | The message to be signed |
Returns:
Promise<object>
Property Name | Type | Description |
---|---|---|
bytes | string | The signed message in base64 format. |
signature | string | The digital signature. |
Usage
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
})
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
// import {Transaction} from "@mysten/sui/transactions";
interface signTransactionInput {
transaction: Transaction
}
// import {Transaction} from "@mysten/sui/transactions";
interface signTransactionInput {
transaction: Transaction
}
// 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 Name | Type | Description |
---|---|---|
bytes | string | The signed message in base64 format. |
signature | string | The digital signature. |
Usage
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})
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 functionbroadcasts
the transaction after signing.
Dapp Demo
transfer coin
<template>
<div>
<button class="bitget-btn" @click="connect">{{address ? 'connected' : 'connect'}}</button>
<input class="bigtet-input" placeholder="amount" v-model="amount"/>
<input class="bigtet-input" placeholder="address" v-model="toAddress"/>
<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>
<input class="bigtet-input" placeholder="amount" v-model="amount"/>
<input class="bigtet-input" placeholder="address" v-model="toAddress"/>
<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
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));