Provider API
SUI wallet standard
Introduction
Sui wallet uses wallet standard, which is somewhat different from other heterogeneous chains. You can obtain the wallet object through event notification:
const GlobalWallet = {
register: (wallet) => {
GlobalWallet[wallet.chainName] = wallet
}
}
const event = new CustomEvent('wallet-standard:app-ready', { detail: GlobalWallet });
window.dispatchEvent(event);
const suiWallet = GlobalWallet.suiMainnet;
// You can also use the official SDK to connect to Nabox
Connect your wallet
const { accounts } = await NaboxWallet.sui.features['standard:connect'].connect();
// accounts
[{
address: '0x0451ff5a1b06f....272366aef69b369',
chains: ['sui:mainnet'],
features: ['sui:signAndExecuteTransactionBlock', 'sui:signTransactionBlock', 'sui:signMessage'],
publicKey: 'sui publicKey'
}]
signAndExecuteTransactionBlock (sign and broadcast transaction)
const txParameters = {
transactionBlock: '', // sui transaction block
options: { showEffects: true }
};
const transactionBlockResponse = await NaboxWallet.sui.features['sui:signAndExecuteTransactionBlock'].signAndExecuteTransactionBlock(txParameters);
interface SuiTransactionBlockResponse {
balanceChanges?: BalanceChange[] | null;
/**
* The checkpoint number when this transaction was included and hence finalized. This is only returned
* in the read api, not in the transaction execution api.
*/
checkpoint?: string | null;
confirmedLocalExecution?: boolean | null;
digest: string;
effects?: TransactionEffects | null;
errors?: string[];
events?: SuiEvent[] | null;
objectChanges?: SuiObjectChange[] | null;
rawEffects?: number[];
/**
* BCS encoded [SenderSignedData] that includes input object references returns empty array if
* `show_raw_transaction` is false
*/
rawTransaction?: string;
timestampMs?: string | null;
/** Transaction input data */
transaction?: SuiTransactionBlock | null;
};
signTransactionBlock (signature transaction)
const txParameters = {
transactionBlockSerialized: '', // sui serialized transaction
options: { showEffects: true }
};
const signedTransaction = await NaboxWallet.sui.features['sui:signTransactionBlock'].signTransactionBlock(txParameters);
// signedTransaction
{
transactionBlockBytes: 'Transaction Bytes',
signature: 'signature string' // Signed transaction hex
}
signMessage(Message Signature)
const messsageParameters = {
message: '' // The specific message needs to be converted to Uint8Array type
};
const signedMessage = await NaboxWalllet.sui.features['sui:signMessage'].signMessage({ message });
// signedMessage
{
signature,
messageBytes
}
Event
// Account Changes
NaboxWalllet.sui.features['standard:events'].on('accountChanged', (publicKey) => {
if (publicKey) {
console.log(publicKey);
}
});
// Connection successful
NaboxWalllet.sui.features['standard:events'].on("connect", () => console.log("connected!"));
// Disconnect
NaboxWalllet.sui.features['standard:events'].on("disconnect", () => console.log("disconnected!"));
Last updated