Installation & Initialization
To integrate OKX Connect with your DApp, ensure you're using OKX App version 6.98.0 or later. Install via npm:
npm install okx-connect-sdkInitialize the provider with required metadata:
const provider = new OKXUniversalProvider({
dappMetaData: {
name: "Your DApp Name",
icon: "https://example.com/icon.png" // 180x180px PNG recommended
}
});Connecting Wallets
Establish wallet connections to retrieve addresses for transaction signing:
Parameters
connectParams:namespaces: Requested chains (currently onlystarknet:mainnet)optionalNamespaces: Fallback chainssessionConfig.redirect: Post-connection redirect (e.g.,tg://resolvefor Telegram Mini Apps)
Response
{
topic: "session_identifier",
accounts: ["0x123...abc"],
chains: ["starknet:mainnet"],
methods: ["signTransaction", "signMessage"]
}Transaction Preparation
Create a provider instance for Starknet transactions:
const starknetProvider = new OKXStarknetProvider(universalProvider);Account Information Retrieval
Request
chainId: Target chain (e.g.,starknet:mainnet)
Response
{
address: "0x123...abc",
pubKey: "0x456...def"
}Message Signing
Parameters
signerAddress: Wallet addresstypedData: Structured message payloadchain: Execution chain (optional)
Response
- Returns
[r, v]signature components
Transaction Signing & Broadcasting
Parameters
signerAddress: Wallet addresstransaction: Structured transaction datachainId: Execution chain (optional)
Response
- Transaction hash string
Disconnecting Wallets
Terminate active sessions before switching wallets:
provider.disconnect();Event Handling
Subscribe to connection state changes:
provider.on("session_update", (event) => {
console.log("Session updated:", event);
});Error Codes
| Code | Description |
|---|---|
| 1000 | Unknown error |
| 1001 | Wallet already connected |
| 1002 | Wallet not connected |
| 3000 | User rejected request |
| 4001 | Method not supported |
| 4002 | Chain not supported |
| 4003 | Unsupported wallet type |
| 5000 | Connection failure |
FAQ
What chains does Starknet SDK currently support?
👉 Currently only Starknet Mainnet is supported
How do I handle user rejection errors?
Implement fallback UX flows when users decline connection requests (error code 3000).
Can I use SVG icons for dApp metadata?
No, only PNG/ICO formats are supported (180x180px recommended).
Is there a mobile SDK for native apps?
Yes, the same SDK works for both web and mobile implementations.
How long do wallet sessions persist?
Sessions remain active until explicitly disconnected or until the user logs out.
What's the maximum transaction size?
Starknet currently supports transactions up to 128KB in size.