Ledger through Keplr Wallet Transaction

On this page, we are going to have a look at the implementation for Injective when your users are using a Ledger device through the Keplr wallet.

As explained before, Injective uses a different derivation curve from the rest of the Cosmos chains which means that the users have to use the Ethereum app (for now) to interact with Injective.

The easiest way all of the edge cases covered and a full out-of-the-box solution for all of the supported wallets on Injective I suggest you have a look at the MsgBroadcaster + WalletStrategy abstraction. If you want to do your own implementation, let's go through the code example together.

Overview

Keplr exposes a experimentalSignEIP712CosmosTx_v0 method which can be utilized to sign EIP712 typed data (automatically generated on the Keplr side by passing a Cosmos StdSignDoc to the method above) and allow EVM-compatible chains to get proper signatures when we have Ledger devices connected through Keplr.

Here is the function's signature:

/**
 * Sign the sign doc with ethermint's EIP-712 format.
 * The difference from signEthereum(..., EthSignType.EIP712) is that this api returns a new sign doc changed by the user's fee setting and the signature for that sign doc.
 * Encoding tx to EIP-712 format should be done on the side using this api.
 * Not compatible with cosmjs.
 * The returned signature is (r | s | v) format which used in ethereum.
 * v should be 27 or 28 which is used in the ethereum mainnet regardless of chain.
 * @param chainId
 * @param signer
 * @param eip712
 * @param signDoc
 * @param signOptions
 */
experimentalSignEIP712CosmosTx_v0(chainId: string, signer: string, eip712: {
    types: Record<string, {
        name: string;
        type: string;
    }[] | undefined>;
    domain: Record<string, any>;
    primaryType: string;
}, signDoc: StdSignDoc, signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;

What we need to do now is generate the eip712 and the signDoc, pass them to this function and Keplr will ask the user to sign the transaction using the Ethereum app on their Ledger device.

Example Implementation

Based on the overview above, let's now showcase a full example of how to implement signing transactions on Injective using Ledger + Keplr. Keep in mind that the example below takes into consideration that you are using the Msgs interface exported from the @injectivelabs/sdk-ts package.

Last updated