Make sure to update to version 6.92.0 or later to get started with access: integrating OKX Connect into your DApp can be done using npm:
npm install @okxconnect/aptos-provider
Before connecting to a wallet, you need to create an object that will be used to connect to the wallet, send transactions and so on.
OKXUniversalProvider.init({dappMetaData: {name, icon}})
Request parameters
Return Value
Examples
import { OKXUniversalProvider } from "@okxconnect/universal-provider";
const okxUniversalProvider = await OKXUniversalProvider.init({
dappMetaData: {
name: "application name",
icon: "application icon url"
},
})
Connect to the wallet to get the wallet address as an identifier and the necessary parameters for signing the transaction;
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: {
aptos: {
chains: ["aptos:mainnet", // aptos mainnet
// "movement:testnet",// movement testnet
],
}
},
sessionConfig: {
redirect: "tg://resolve"
}
})
Gets whether the wallet is currently connected.
Return Value
Example
okxUniversalProvider.connected();
First create an OKXAptosProvider object, with the constructor passing in OKXUniversalProvider
import { OKXAptosProvider } from '@okxconnect/aptos-provider';
let okxAptosProvider = new OKXAptosProvider(okxUniversalProvider)
Get the wallet address and publicKey
okxAptosProvider.getAccount(chain);
Request Parameters
Return Value
okxAptosProvider.signMessage(message, chain)
Request parameters
Return value
address: string;
application: string;
chainId: number;
fullMessage: string; // The message that was generated to sign
message: string; // The message passed in by the user
nonce: string;
prefix: string; // Should always be APTOS
signature: string; // The signed full message
okxAptosProvider.signTransaction(transaction, chain)
Request Parameters
Return Value
okxAptosProvider.signAndSubmitTransaction(transactions, chain)
Request Parameters
Return Value
Example
// Signature message
let data = {
address:true,
application:true,
chainId:true,
message:"Hello OKX",
nonce:"1234"
}
let provider = new OKXAptosProvider(window.provider)
let message = await provider.signMessage(data, "aptos:mainnet")
//return value {‘address’: ‘0x2acddad65c27c6e5b568b398f0d1d01ebb8b55466461bbd51c1e42763a92fdfe’, ‘application’: ‘http://192.168.101.13’,"’ chainId": “aptos:mainnet”, “fullMessage”: ’APTOS\naddress: 0x2acddad65c27c6e5b568b398f0d1d01ebb8b55466461bbd51c1e42763a92fdfe\ napplication: http://192.168.101.13\nchainId: aptos:mainnet\nmessage: 123 Signature Test! \nnonce: 1234’, “message”: ’123 Signature test!’ , ‘nonce’: ‘1234’, ‘prefix’: ‘APTOS’, ‘signature’:’ 0xef4e587f537b80a2f4e424079984b80e130c92d939a92225764be00ed36486521e8857b8a222de4023c5f4d2e9fd2f62c26ca8a43694660583c8a5d4328da303 ’, ‘verified’:true}
// Sign the transaction and upload it
const config = new AptosConfig({ network: Network.MAINNET });
const aptos = new Aptos(config);
// Support for transactions created via @aptos-labs/ts-sdk
const transaction = await aptos.transaction.build.simple({
sender: "0x07897a0496703c27954fa3cc8310f134dd1f7621edf5e88b5bf436e4af70cfc6",
data: {
function: "0x80273859084bc47f92a6c2d3e9257ebb2349668a1b0fb3db1d759a04c7628855::router::swap_exact_coin_for_coin_x1",
typeArguments: ["0x1::aptos_coin::AptosCoin", "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::stapt_token::StakedApt", "0x0163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::curves::Uncorrelated", "0x80273859084bc47f92a6c2d3e9257ebb2349668a1b0fb3db1d759a04c7628855::router::BinStepV0V05"],
functionArguments: ["10000", ["9104"], ["5"], ["true"]],
},
});
let result1 = await provider.signAndSubmitTransaction(transaction, "aptos:mainnet")
//Support transactions in the following data formats at the same time
let transactionData = {
"arguments": ["100000",["0","0","10533"],["10","5","5"],["false","false","true"]],
"function": "0x80273859084bc47f92a6c2d3e9257ebb2349668a1b0fb3db1d759a04c7628855::router::swap_exact_coin_for_coin_x3",
"type": "entry_function_payload",
"type_arguments": ["0x1::aptos_coin::AptosCoin","0x73eb84966be67e4697fc5ae75173ca6c35089e802650f75422ab49a8729704ec::coin::DooDoo","0x53a30a6e5936c0a4c5140daed34de39d17ca7fcae08f947c02e979cef98a3719::coin::LSD","0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC","0x80273859084bc47f92a6c2d3e9257ebb2349668a1b0fb3db1d759a04c7628855::router::CurveV1","0x0163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::curves::Uncorrelated","0x0163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::curves::Uncorrelated","0x54cb0bb2c18564b86e34539b9f89cfe1186e39d89fce54e1cd007b8e61673a85::bin_steps::X80","0x80273859084bc47f92a6c2d3e9257ebb2349668a1b0fb3db1d759a04c7628855::router::BinStepV0V05","0x80273859084bc47f92a6c2d3e9257ebb2349668a1b0fb3db1d759a04c7628855::router::BinStepV0V05"]
}
let result2 = await provider.signAndSubmitTransaction(transactionData, "movement:testnet")
Disconnect the connected wallet and delete the current session. If you want to switch the connected wallet, please disconnect the current wallet first.
okxUniversalProvider.disconnect();