Connect to Extension Wallet

Provider API#

What is injected provider API?#

The OKX injected provider API is a JavaScript API that OKX injects into websites visited by our users. Your DApp can use this API to request users' accounts, read data from blockchains users are connected to, and help users sign messages and transactions.

Note: Cosmos is only supported on the OKX browser extension.

Connecting to OKX Wallet#

window.okxwallet.keplr.enable(chainIds)

Description

If OKX Wallet is locked, you can unlock the wallet by using window.keplr.enable(chainIds). You'll be required to grant the webpage permission to access Keplr if such permission wasn't previously granted.

The enable method can receive one or more chain IDs as an array. When passing the chain ID array, you can simultaneously request the permissions of all chains that haven't been authorized. If you cancel the unlocking or are denied permission, an error will show.

enable(chainIds: string | string[]): Promise<void>

Example

Open in codeopen.

<button class="connectCosmosButton">Connect Cosmos</button>

Signing transactions#

window.okxwallet.keplr.signAmino(chainId, signer, signDoc)

Description

This request signs in a fixed format, similar to the signAmino method of OfflineSigner of cosmjs. Parameters are objects, and signDoc is a fixed format.

window.okxwallet.keplr.signAmino(chainId: string, signer: string, signDoc: StdSignDoc, signOptions: any): Promise<AminoSignResponse>

Example

Open in codeopen.

<button class="connectCosmosButton btn">Connect Cosmos</button>
<button class="signTransactionButton btn">Sign Transaction</button>

Signing messages#

window.okxwallet.keplr.signArbitrary(chainId, signer, data)

Description

This request will sign any information, which is equivalent to the signMessage (any) of the previous chains.

signArbitrary(
    chainId: string,
    signer: string,
    data: string | Uint8Array
): Promise<StdSignature>;
verifyArbitrary(
    chainId: string,
    signer: string,
    data: string | Uint8Array,
    signature: StdSignature
): Promise<boolean>;

Example

Open in codeopen.

<button class="connectCosmosButton btn">Connect Cosmos</button>
<button class="signMessageButton btn">Sign Message</button>

Events#

Connecting to OKX Wallet You can connect to OKX Wallet by calling window.okxwallet.keplr.enable(chainId). When the user approves the connection request, the connection event will be triggered.

Usage

window.okxwallet.keplr.on("connect", () => console.log("connected!"));

Example

Open in codeopen.

<button class="connectCosmosButton">Connect Cosmos</button>