Methods
enable
Authorize the dApp to access one or more Cosmos chains.
Request
window.keplr.enable(chainId: string | string[])
Response
void (throws if rejected)
Example
// Single chain
await window.keplr.enable("cosmoshub-4");
// Multiple chains
await window.keplr.enable(["cosmoshub-4", "osmo-test-5"]);
getKey
Get the public key and address information for a given chain.
Request
{
chainId: string;
}
Response
{
name: string;
algo: string;
pubKey: Uint8Array;
address: Uint8Array;
bech32Address: string;
ethereumHexAddress: string;
isNanoLedger: boolean;
isKeystone: boolean;
}
Example
const key = await window.keplr.getKey("osmo-test-5");
console.log(key.bech32Address);
// "osmo1fjnqlywrnpj4923dsga7qf5ucvxd7ujmw3ypgv"
signAmino
Sign a transaction in Amino (legacy) format.
Request
{
chainId: string;
signer: string;
signDoc: AminoSignDoc;
signOptions?: SignOptions;
}
Response (AminoSignResponse)
{
signed: AminoSignDoc;
signature: {
pub_key: {
type: string;
value: string;
};
signature: string;
}
}
Example
const result = await window.keplr.signAmino(
"osmo-test-5",
"osmo1fjnqlywrnpj4923dsga7qf5ucvxd7ujmw3ypgv",
{
chain_id: "osmo-test-5",
account_number: "168594",
sequence: "4",
fee: { gas: "265431", amount: [{ denom: "uosmo", amount: "6636" }] },
msgs: [
{
type: "cosmos-sdk/MsgDelegate",
value: {
delegator_address: "osmo1fjnqlywrnpj4923dsga7qf5ucvxd7ujmw3ypgv",
validator_address: "osmovaloper1unurj3mamew8msxy8p7yltmzgvf0dx42aduz33",
amount: { denom: "uosmo", amount: "1300000" }
}
}
],
memo: ""
},
{}
);
console.log(result.signature.signature);
signDirect
Sign a transaction in Direct (Protobuf) format.
Request
{
chainId: string;
signer: string;
signDoc: DirectSignDoc;
signOptions?: SignOptions;
}
Response (DirectSignResponse)
{
signed: DirectSignDoc;
signature: {
pub_key: {
type: string;
value: string;
};
signature: string;
}
}
signArbitrary
Sign arbitrary data for off-chain authentication purposes.
Request
{
chainId: string;
signer: string;
data: string;
}
Response
{
pub_key: {
type: string;
value: string;
};
signature: string;
}
Example
const result = await window.keplr.signArbitrary(
"cosmoshub-4",
"cosmos1ef9u3zq2sl4egd0wpmmrzkpzrw3dq247ad8e8w",
"Sign in with Cactus Link"
);
console.log(result.signature);
sendTx
Broadcast a signed transaction to the network.
Request
{
chainId: string;
tx: Uint8Array;
mode: BroadcastMode;
}
BroadcastMode values
| Value | Description |
|---|---|
"block" |
Wait for tx to be committed in a block |
"sync" |
Return after CheckTx passes |
"async" |
Return immediately |
Response
Transaction hash bytes (Uint8Array)
Example
const txHash = await window.keplr.sendTx(
"osmo-test-5",
signedTxBytes,
"sync"
);
console.log(txHash);
isConnected
Check whether the wallet is currently connected to the dApp.
Response
boolean
Example
const connected = await window.keplr.isConnected();
console.log(connected); // true or false
disconnect
Disconnect the wallet from the dApp.
Example
await window.keplr.disconnect();
getSupportChains
Get the list of chains supported by the wallet.
Response
string[] — array of chain IDs
Example
const chains = await window.keplr.getSupportChains();
console.log(chains);
// ["cosmoshub-4", "osmosis-1", ...]
verifyArbitrary
Verify an arbitrary signature.
Not yet supported.
Request
{
chainId: string;
signer: string;
data: string;
signature: string;
}
Response
boolean