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/sui-provider
Before connecting the wallet, you need to create an object for subsequent wallet connections, transaction submissions, and other operations.
OKXUniversalProvider.init({dappMetaData: {name, icon}})
Request parameters
Returns a value.
Example
import { OKXUniversalProvider } from "@okxconnect/universal-provider"
const okxUniversalProvider = OKXUniversalProvider.init({dappMetaData: {
name: "application name",
icon: "application icon url"
}})
Connect the wallet to obtain the wallet address, which serves as an identifier and is necessary for signing transactions.
okxUniversalProvider.connect(connectParams: ConnectParams);
Request Parameters
Return Value
<SessionTypes.Struct | undefined>
Record<string, Namespace>
; namespace information for a successful connection;
Example
var session = await okxUniversalProvider.connect({
namespaces: {
sui: {
chains: ["sui:mainnet"]
}
},
sessionConfig: {
redirect: "tg://resolve"
}
})
Disconnect from a connected wallet and delete the current session. If you want to switch wallets, disconnect from the current wallet first.
Example
okxUniversalProvider.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(okxUniversalProvider)
SignMessage
suiProvider.signMessage(input: SuiSignMessageInput);
Request Parameters
Return Value
SignPersonalMessage
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)
Sign Transaction
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
Signs a transaction and broadcasts onchain
suiProvider.signAndExecuteTransaction(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
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)