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/solana-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 = await 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
connectParams - ConnectParams
Promise <SessionTypes.Struct | undefined>
Record<string, Namespace>
; namespace information for a successful connection;
Example
var session = await okxUniversalProvider.connect({
namespaces: {
solana: {
chains: ["solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp", //solana mainnet
"solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",//solana testnet
"sonic:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"// sonic testnet
],
}
},
sessionConfig: {
redirect: "tg://resolve"
}
})
This method allows sending messages to the wallet, supporting signatures, transactions, and RPC requests.
First create an OKXSolanaProvider object, passing OKXUniversalProvider into the constructor.
import { OKXSolanaProvider } from "@okxconnect/solana-provider/OKXSolanaProvider";
let okxSolanaProvider = new OKXSolanaProvider(okxUniversalProvider)
okxSolanaProvider.signMessage(message, chain);
Request Parameters
Return Value
okxSolanaProvider.signTransaction(transaction, chain);
Request parameters
Return value
Signs multiple transactions
okxSolanaProvider.signAllTransactions(transactions, chain);
Request parameters
Return value
okxSolanaProvider.signAllTransactions(transactions, chain);
**Request Parameters
**Return Value
okxSolanaProvider.getAccount(chain);
Request Parameters
Return Value
Example
// Signing a transfer transaction on solana mainnet
let provider = new OKXSolanaProvider(okxUniversalProvider)
const transaction = new Transaction({
feePayer: new PublicKey(provider.getAccount().address),
recentBlockhash: "xNWbUfdEPktMsZQHY6Zk5RJqamWFcTKasekjr7c3wFX",
}).add(SystemProgram.transfer(
{
fromPubkey: new PublicKey(provider.getAccount().address),
toPubkey: new PublicKey(provider.getAccount().address),
lamports: 1000,
}
))
let result = await provider.signTransaction(transaction, "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp")
Disconnect from a connected wallet and delete the current session. If you want to switch wallets, disconnect from the current wallet first.
okxUniversalProvider.disconnect();