In addition to SDK, we also provide a UI interface. If using the UI connection, and the DApp is operating in Telegram, users can choose to open the mobile App Wallet or stay in Telegram and launch the OKX Mini Wallet.
Make sure to update the OKX App to version 6.90.1 or later to start accessing it:
To integrate OKX Connect into your DApp, you can use npm:
npm install @okxconnect/ui
npm install @okxconnect/sui-provider
Before connecting to a wallet, you need to create an object that can provide a UI interface for subsequent operations such as connecting to the wallet and sending transactions.
OKXUniversalConnectUI.init(dappMetaData, actionsConfiguration, uiPreferences, language)
Request parameters
${string}://${string}
; for app wallet, specify the return strategy for the deep link when the user signs/rejects the request, if it is in tg, you can configure tg://resolve${string}://${string}
; For Telegram Mini Wallet, specify the return policy of deep link when user signs/rejects the request, if it's in tg, you can configure tg://resolve none means no processing after signing; default is back;Return Value
Example
import { OKXUniversalConnectUI } from "@okxconnect/ui";
const okxUniversalConnectUI = await OKXUniversalConnectUI.init({
dappMetaData: {
icon: "https://static.okx.com/cdn/assets/imgs/247/58E63FEA47A2B7D7.png",
name: "OKX Connect Demo"
},
actionsConfiguration: {
returnStrategy: 'tg://resolve',
modals:"all"
},
language: "en_US",
uiPreferences: {
theme: THEME.LIGHT
},
});
Connecting to a wallet goes to get the wallet address, which serves as the identifier and the necessary parameters used to sign the transaction.
okxUniversalConnectUI.connect(connectParams: ConnectParams);
Request Parameters
Return value
<SessionTypes.Struct | undefined>
Record<string, Namespace>
; namespace information for a successful connection;
Example
var session = await okxUniversalConnectUI.connect({
namespaces: {
sui: {
chains: ["sui:mainnet"]
}
},
sessionConfig: {
redirect: "tg://resolve"
}
})
Example
okxUniversalConnectUI.disconnect();
This method allows sending messages to the wallet, supporting signatures, transactions, and RPC requests.
First create an OKXSuiProvider object, passing OKXUniversalProvider into the constructor.
import { OKXSuiProvider } from "@okxconnect/sui-provider"
let suiProvider = new OKXSuiProvider(okxUniversalConnectUI)
suiProvider.getAccount();
Returns the value.
Example
let result = suiProvider.getAccount()
// Return structure
{
'address": “0x7995ca23961fe06d8cea7da58ca751567ce820d7cba77b4a373249034eecca4a”,
'publicKey": “tUvCYrG22rHKR0c306MxgnhXOSf16Ot6H3GMO7btwDI=”,
}
suiProvider.signMessage(input: SuiSignMessageInput);
Request Parameters
Return Value
suiProvider.signPersonalMessage(input: SuiSignMessageInput);
Request Parameters
Return Value
Example
const data = [76, 111, 103, 105, 110, 32, 119, 105, 116, 104, 32, 66, 108, 117, 101, 109, 111, 118, 101];
const uint8Array = new Uint8Array(data);
let input = {
message: uint8Array
}
let signResult1 = await suiProvider.signMessage(input)
let signResult2 = await suiProvider.signPersonalMessage(input)
suiProvider.signTransaction(input);
Request Parameters
// txBytes and txSerialize are the serialization of the transactionBlock.
// and transactionBlock can be passed in one way or the other, but not both.
interface SuiSignTransactionBlockInput {
transactionBlock: TransactionBlock;
chain: IdentifierString;
txBytes: string?;
txSerialize: string?
}
Return Value
suiProvider.signAndExecuteTransaction(input);
Request Parameters
// txBytes and txSerialize is Serialized from transactionBlock,
// if you pass transactionBlock, then no need to pass txBytes and txSerialize
interface SuiSignTransactionBlockInput {
transactionBlock: TransactionBlock;
chain: IdentifierString;
txBytes: string?;
txSerialize: string?;
}
Return Value
Example
// Define the amount to be transferred and the destination address
const amount = 109; // Amount to be transferred
const recipientAddress = '0x'; // destination address
/// Construct a transfer transaction
const tx = new Transaction();
const [coin] = tx.splitCoins(tx.gas, [amount]);
tx.transferObjects([coin], recipientAddress)
const input = {
transactionBlock: tx,
chain: 'sui:mainnet',
options: {
showEffects: true,
}
}
let signResult1 = await suiProvider.signTransaction(input)
let signResult2 = await suiProvider.signAndExecuteTransaction(input)
Disconnect from a connected wallet and delete the current session. If you want to switch wallets, disconnect from the current wallet first.